使用反射自定义if语句 [英] Custom if statement using reflection
问题描述
嘿,如果可以将文本解析为if语句,并且也添加了and,or和xor,那么我全神贯注,所以可以说我是否在列表中有一些标记,如下所示:
如果某变量,等值,另一个变量和/或/或某变量等值或第三变量做某事.
应该翻译成if(var1 == var2 &&/||/^ var1 == var3){body}
目前,我可以使它适用于单个语句/布尔表达式,但是我真的迷失了如何使用反射来检查乘法.它必须与ands和ors进行两次以上的比较,因此它必须能够将它称为递归性.因此,如果有任何解决方案,我希望收到您的回音-非常感谢.
-Jackie
Hey all i was wondring if it is possible to parse text to an if statement and also have and, or, and xor added to so lets say if i have some tokens in a list as following:
if, someVarible, isequal, anothervarible, and /or/xor someVarible isequal aathirdvarible do something.
that should be translated into if(var1 == var2 &&/||/^ var1 == var3) { body }
at the moment i can make it work for a single statement/boolean expression but im really lost how i can check for multiply by using the reflections. it migth be more than 2 comparisons that is needed with both ands and ors so it must be able to call it recrusive. so if any one out there have a solution i would love to hear from you - thanks a lot.
-Jackie
推荐答案
这可能会有所帮助: http ://www.jarloo.com/c-formula-evaluator/ [ ^ ].它使用正则表达式来解析文本.
This might be of some help: http://www.jarloo.com/c-formula-evaluator/[^]. It uses regular expressions to parse the text.
此代码项目文章
数学/函数/布尔/字符串表达式评估器 [ ^ ]
可能也有帮助.
This Code Project article
math / function / boolean /string expression evaluator[^]
may also be helpful.
这篇关于使用反射自定义if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!