How can I evaluate C# code dynamically?

后端 未结 16 2268
[愿得一人]
[愿得一人] 2020-11-22 03:37

I can do an eval(\"something()\"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#?

An example of what I

16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 04:10

    I don't now if you absolutely want to execute C# statements, but you can already execute Javascript statements in C# 2.0. The open-source library Jint is able to do it. It's a Javascript interpreter for .NET. Pass a Javascript program and it will run inside your application. You can even pass C# object as arguments and do automation on it.

    Also if you just want to evaluate expression on your properties, give a try to NCalc.

提交回复
热议问题