eval(string) to C# code

后端 未结 8 1943
傲寒
傲寒 2021-01-19 04:23

Is it possible to evaluate the following in C# at runtime

I have a class that contains 3 properties (Field,Operator,Value)

8条回答
  •  北海茫月
    2021-01-19 04:50

    No, C# doesn't support anything like this directly.

    The closest options are:

    • Create a full valid C# program and dynamically compile it with CSharpCodeProvider.
    • Build an expression tree, compile and execute it
    • Perform the evaluation yourself (this may actually be easiest, depending on your operators etc)

提交回复
热议问题