Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
How to build a Roslyn syntax tree from scratch?

I want to do some very basic code-gen (converting a service API spec to some C# classes for communicating with the service). I found this question that seems to suggest I can call Syntax.CompilationUnit() to create a new CompilationUnityntax, however I'm unable to make this code compile; I can't find a CompilationUnit method on any of the Syntax classes I can find (nor can I locate any docs on this) :(

CSharpSyntaxTree.Create appears to need a CSharpSyntaxNode, but I can't figure out how to create one of them either :/

I'm using VS 2015 RC with the latest Microsoft.CodeAnalysis NuGet package (1.0.0-rc2).

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Seems that Syntax is now SyntaxFactory:

var comp = SyntaxFactory.CompilationUnit()
        .AddMembers(
            SyntaxFactory.NamespaceDeclaration(SyntaxFactory.IdentifierName("ACO"))
                    .AddMembers(
                    SyntaxFactory.ClassDeclaration("MainForm")
                        .AddMembers(
                            SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName("System.Windows.Forms.Timer"), "Ticker")
                                    .AddAccessorListAccessors(
                                    SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
                                    SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))),
                            SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName("void"), "Main")
                                    .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
                                    .WithBody(SyntaxFactory.Block())
                            )
                    )
            );
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!