有没有什么办法可以在运行时在c#中将一串代码转换为可执行代码?在运行时将字符串转换为可执行代码在c#中?
所以,如果我有谓词
This is normal text in a txt file
u => u.Contains("android") && u.Contains("webkit")
u => u.Contains("iphone") && u.Contains("webkit")
我希望通过我的程序读取它,然后捕获每个谓词作为一个字符串,然后将其转换为在运行代码的文件。喜欢的东西:
string[] predicates = ///get file contentsa
foreach(var predicate in predicates)
{
if(userAgent.ConformsTo(eval(predicate))) return true;
}