Is Roslyn ".WithFooToken ()" redundant?

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?

+6
source share
2 answers

Yes, in simple cases, these challenges are not needed. RoslynQuoter code has a RemoveRedundantModifyingCalls parameter, which I believe should do exactly what you want. But it is not implemented, the only use is commented out :

 private void AddModifyingCall(ApiCall apiCall, MethodCall methodCall) { // TODO: this needs scripting ////if (RemoveRedundantModifyingCalls) ////{ //// var before = Evaluate(apiCall, UseDefaultFormatting); //// apiCall.Add(methodCall); //// var after = Evaluate(apiCall, UseDefaultFormatting); //// if (before == after) //// { //// apiCall.Remove(methodCall); //// } ////} apiCall.Add(methodCall); return; } 
+5
source
Answer to

@svick is correct. I just forgot to re-enable this code because Roslyn Scripting was not available.

Now that Scripting is publicly available, I have included this code again and updated the website: http://roslynquoter.azurewebsites.net/

Try the website right now, and extra calls, as you mentioned above, should disappear (they will still appear when they are needed to change little things / comments, etc.).

+7
source

All Articles