有没有办法在C#中编译以下字符串?
string linqExpression = "(seq) => seq.Average()"
使用roslyn?
而不是这样做:
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(@" using System;
using System.Linq;
public class RoslynLinq
{
public void Execute(int[] a)
{
Func<int[], double> func = (seq) => seq.Average();
Console.WriteLine(func(a));
}
}");
我可以这样做:
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText("Func<int[], double> func = (seq) => seq.Select((x)=>x).Average()");