using System; using Roslyn.Compilers.CSharp; namespace HelloRoslyn { class Program { static void Main() { string program = Syntax.CompilationUnit( usings: Syntax.List(Syntax.UsingDirective(name: Syntax.ParseName("System"))), members: Syntax.List<MemberDeclarationSyntax>( Syntax.NamespaceDeclaration( name: Syntax.ParseName("HelloRoslyn"), members: Syntax.List<MemberDeclarationSyntax>( Syntax.ClassDeclaration( identifier: Syntax.Identifier("Program"), members: Syntax.List<MemberDeclarationSyntax>( Syntax.MethodDeclaration( returnType: Syntax.PredefinedType(Syntax.Token(SyntaxKind.VoidKeyword)), modifiers: Syntax.TokenList(Syntax.Token(SyntaxKind.StaticKeyword)), identifier: Syntax.ParseToken("Main"), parameterList: Syntax.ParameterList(), bodyOpt: Syntax.Block( statements: Syntax.List<StatementSyntax>( Syntax.ExpressionStatement( Syntax.InvocationExpression( Syntax.MemberAccessExpression( kind: SyntaxKind.MemberAccessExpression, expression: Syntax.IdentifierName("Console"), name: Syntax.IdentifierName("WriteLine"), operatorToken: Syntax.Token(SyntaxKind.DotToken)), Syntax.ArgumentList( arguments: Syntax.SeparatedList( Syntax.Argument( expression: Syntax.LiteralExpression( kind: SyntaxKind.StringLiteralExpression, token: Syntax.Literal("\"Hello world\"", "Hello world") ) ) ) ) ) ) ) ) ) ) ) ) ) )).Format().GetFullText(); Console.WriteLine(program); } } }
October 20, 2011
Hello Roslyn
3 Comments »
RSS feed for comments on this post. TrackBack URI
Ha-ha, reminds me of http://www.charlespetzold.com/etc/CSAML.html
I wonder if anyone has already tried building a quine with Roslyn
Comment by Kirill Osenkov — October 20, 2011 @ 1:14 pm
Comment by Jacob — October 20, 2011 @ 2:20 pm
How do you change the language it prints to be VB?
Comment by justinmchase chase — December 6, 2011 @ 3:32 pm