I am trying to use the Roslyn code generation capabilities using LinqPad to run snippets. The LinqPad.Dump () extension method displays a formatted view of an object in the results pane.
The code generated by http://roslynquoter.azurewebsites.net/ contains a lot of code that seems to do nothing but add bloat. The following code prints return null; whether .WithFooToken(...) tags are commented out or not.
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; var syn = SyntaxFactory.ReturnStatement( SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression) // .WithToken(SyntaxFactory.Token(SyntaxKind.NullKeyword)) ) // .WithReturnKeyword( // SyntaxFactory.Token(SyntaxKind.ReturnKeyword) // ) // .WithSemicolonToken( // SyntaxFactory.Token(SyntaxKind.SemicolonToken) // ) ; syn.NormalizeWhitespace().ToFullString().Dump();
Are such calls optional for all languages, or only for languages ββthat have reasonable defaults built into their Roslyn support libraries?
source share