如何将此转换为表达式树或使用linq,以便我可以在这些表达式层次上编写函数库?C#中的表达树
我已经看到了这个库,但我不知道我是正确的道路上https://csharpeval.codeplex.com/wikipage?title=Usage&referringTitle=Documentation
max(avg(high1:3),avg(low1:3)) - min(avg(high1:3),avg(low1:3))
如何将此转换为表达式树或使用linq,以便我可以在这些表达式层次上编写函数库?C#中的表达树
我已经看到了这个库,但我不知道我是正确的道路上https://csharpeval.codeplex.com/wikipage?title=Usage&referringTitle=Documentation
max(avg(high1:3),avg(low1:3)) - min(avg(high1:3),avg(low1:3))
编译并在运行时执行代码始终是一个挑战。 您提到的图书馆只是一种方式。
您可以使用由Microsoft和C#团队随C#6.0和Visual Studio 2015提供的Roslyn。你无法想象它有多强大。下面是一些示例和演练:
https://github.com/dotnet/roslyn/wiki/Samples-and-Walkthroughs
和其他一些介绍:
https://en.wikipedia.org/wiki/.NET_Compiler_Platform
,这里是一些样本来创建一个REPL(像你想要的):
http://www.jayway.com/2015/05/09/using-roslyn-to-build-a-simple-c-interactive-script-engine/
使用Roslyn可以简单地有一些hing是这样的:
var csScript =
string.Format(@"
var x = Math.Max(Math.Avg({0},3),Math.Avg(low1:3));
x;
", high1, low1);
//And this from the REPL
Console.WriteLine(CSharpScriptEngine.Execute(csScript));
这似乎不是C# –