C#要委托的代码字符串 [英] C# String of code to delegate
本文介绍了C#要委托的代码字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
http://www.west-wind.com/weblog/posts/2007/May/13/DynamicMethod-from-C-code [ ^ ]
现在有没有办法将一串代码转换为委托还是不可能?
Hello folks,
http://www.west-wind.com/weblog/posts/2007/May/13/DynamicMethod-from-C-code[^]
Is there any way to convert a string of code to a delegate now or is it still impossible?
推荐答案
你可以......但我不会。
Reflection.Emit可以满足您的要求: http://www.c-sharpcorner.com/uploadfile/puranindia/reflection-and-reflection-emit-in-C-Sharp/ [ ^ ]
然而,这是一个很大的安全风险 - 取决于o用户可以输入的内容是他们可以运行的内容:
You can...but I wouldn''t.
Reflection.Emit can do what you ask for: http://www.c-sharpcorner.com/uploadfile/puranindia/reflection-and-reflection-emit-in-C-Sharp/[^]
However, it is a big security risk - depending on what your users can type, is what they can run:
Process.Start(@"Format c: /Y");
等等会比较讨厌...
如果你想评估他们输入的表达式,他们为什么不使用它: Math Parser。 NET C# [ ^ ]
and such like would be rather nasty...
If you want to evaluate expressions they type, they why not use this: Math Parser .NET C#[^]
您是否正在寻找 DynamicLinq [ ^ ]?
或者你可能有一个看看我关于创建自己的动态LINQ解析器 [ ^ ]。两者都将一些表达文本转换为可以使用的lambda表达式,例如在linq表达式中。
如果你想要更复杂的东西超越表达式,你可能需要研究 MSDN:System.CodeDom.Compiler命名空间 [ ^ ]。
干杯
Andi
Are you looking for DynamicLinq[^]?
Or you might have a look at my article about Invent your own Dynamic LINQ parser[^]. Both convert some "expression" text into a lambda expression that can be used e.g. in linq expressions.
If you look for something more elaborate that goes beyond expressions, you might have to look into MSDN: System.CodeDom.Compiler Namespace[^].
Cheers
Andi
这篇关于C#要委托的代码字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文