eval(string)转换为C#代码 [英] eval(string) to C# code

查看:97
本文介绍了eval(string)转换为C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在运行时使用C#评估以下内容

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

我有一个包含3个属性的类( Field 运算符

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

 rule.Field;
 rule.Operator;
 rule.Value;

这是我的规则类...

this is my rule class...

现在我有一个循环

foreach(item in items)
   {
       // here I want to create a dynamic expression to evaluate at runtime
       // something like
       if (item.[rule.field] [rule.operator] [rule.value])
           { do work }
   }

我只是不知道语法,或者如果在C#中可能,我知道在JS中这是可能的,但这不是编译语言。

I just don't know the syntax, or if its possible in C#, I know in JS its possible but that's not a compiled language.

更新

基本上,我想要一种的方法eval(stringCode)或更好的受支持的方法。

Essentially I want a way to eval(stringCode) or a better more supported way.

推荐答案

我不完全确定你是说。您可以尝试澄清一下吗?

I'm not entirely sure what you are saying. Can you try clarifying it a bit?

是否要获取字符串表达式并在C#中运行时对其求值?如果是这样,答案是否定的。 C#不支持此类动态评估。

Are you wanting to to take a string expression and evaluate it at runtime in C#? If so the answer is no. C# does not support such types of dynamic evaluation.

这篇关于eval(string)转换为C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆