Convert string to executable code at run time in c#?

前端 未结 2 959
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 15:46

Is there any way I can convert a string of code into executable code at runtime in c#?

So if I have a file of predicates

This is normal text in a txt         


        
相关标签:
2条回答
  • 2021-01-03 16:35

    You can use CSharpCodeProvider class, but you'll need to build quite a bit of extra code around the snippet, as you have to provide a full class. I did this for my "Snippy" tool for C# in Depth, and you can download the source to get one simple example of how it can be done.

    However, life is becoming much simpler in this area with Roslyn - you may want to get hold of the CTP and explore that.

    0 讨论(0)
  • 2021-01-03 16:49

    Have a look at the Roslyn ScriptEngine.

    0 讨论(0)
提交回复
热议问题