将以字符串形式编写的IF条件解析为C#代码 [英] Parse a IF Condition written in the String to C# Code
本文介绍了将以字符串形式编写的IF条件解析为C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
条件:
如果A> B THEN
打印B
ELSE
打印A
此条件在SQL的表的列中以字符串形式编写.
我想从表中获取此条件,并将该条件转换为C#代码,如
如果(A> B)
{
打印B ...........
}
其他
{
打印A ...........
}
其中A和B是在C#中传递的动态值.
Example:
Condition:
IF A > B THEN
PRINT B
ELSE
PRINT A
This condition is written as a string in coloumn of the table in SQL.
I want to fetch this condition from the table and convert this condition to the C# Code as
If(A > B )
{
print B...........
}
else
{
print A...........
}
Where A and B are the Dynamic values passed in the C#.
推荐答案
为此,可以使用表达式求值器.
本文可能对您有帮助
数学/函数/布尔/字符串表达式评估器 [ ^ ]
来自上述文章的以下段落
因此,我开发了一组简单的类,称为ExpressionEval和FunctionEval.这些评估器处理数字,字符串,布尔值和日期时间数据类型,并且它们支持C#中可用的所有一元和二进制运算符.它们还支持函数(通过使用FunctionEval类),并具有通过附加事件处理程序来添加自定义函数的功能,该事件处理程序将在找不到函数名称时触发."
可以看到可以处理字符串.
For this purpose the expression evaluator can be used.
This article may be helpful to you
math / function / boolean /string expression evaluator[^]
From the following paragraph of the above article
"Thus, I''ve developed a set of simple classes called ExpressionEval and FunctionEval. These evaluators handle numeric, string, boolean, and datetime datatypes, and they support all the unary and binary operators available in C#. They also support functions (through the utilization of FunctionEval class) and have the ability to add custom functions by attaching an event handler that fires when a function name is not found."
it can be seen that strings can be handled.
这篇关于将以字符串形式编写的IF条件解析为C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文