0

I am trying to generate code using SyntaxFactory but stuck in converting one area Please see the code below I left comment where I am finding it difficult and used string manipulation.

The idea is there will be two variable removeExpression and getExpression which are of type ExpressionSyntax and finally both will be used to become the body of a anonymous function.

ExpressionSyntax removeExpression = SyntaxGenerator.MethodInvokeExpression(
  valueExpression,
  "RemoveAt",
  BinaryExpression(
   SyntaxKind.SubtractExpression,
   SyntaxGenerator.PropertyAccessExpression(valueExpression, nameof(Enumerable.Count)),
   atExpression
  )
 );

ExpressionSyntax getExpression = SyntaxGenerator.MethodInvokeExpression(valueExpression, nameof(Enumerable.First));

// Help me to convert the below line using SyntaxFactory.

IdentifierName("((Func<dynamic>)(() => { var res = " + getExpression.ToString() + ";" + removeExpression.ToString() + "; return res" + " ; }))(); ");

user3048027
  • 387
  • 1
  • 5
  • 24
  • Have you tried using the [roslyn quoter](http://roslynquoter.azurewebsites.net/) and putting in the code you want to get the syntax for the generator? – John Koerner Apr 11 '20 at 20:06
  • Yep tried using roslyn quoter but it was giving wrong result because I was using expression as variable – user3048027 Apr 12 '20 at 02:38

0 Answers0