WinRT C#动态表达式求值程序

时间:2015-09-10 12:24:08

标签: c# windows-runtime

我的应用程序中要求在WinRT c#应用程序中运行时评估字符串表达式。

以下是一些示例表达式:

strObj.Substring(10) + strObj.Substring(strObj.Length - 3) 
'001' + strObj.Substring(3) + '003'

注意:上面的表达式将在后端定义,应用程序应在运行时通过用户输入进行评估。

我查看了DynamicExpresso,NReco和其他一些表达式评估程序,这些都不适用于WinRT环境。 WinRT中是否有可用的框架?或者我如何在代码中实现它?

1 个答案:

答案 0 :(得分:-1)

您也可以尝试DynLan-它也支持PCL / net3.5 / net.core(https://github.com/b-y-t-e/DynLan)。该库本身解析代码并逐行执行。这是您的表达式的一个小示例(结果==“ klmnoprstuwxyzxyz”):

            var dict = new Dictionary<string, object>();
            dict["strObj"] = "abcdefghijklmnoprstuwxyz";

            object result = new Compiler().
                Compile(@" strObj.Substring(10) + strObj.Substring(strObj.Length - 3) ").
                Eval(dict);

您还可以在脚本内部使用变量,例如(结果==“ ABCDEPRSTU”):

            var dict = new Dictionary<string, object>();
            dict["strObj"] = "abcdefghijklmnoprstuwxyz";

            object result = new Compiler().
                Compile(
                    @" a = strObj.Substring(0, 5).ToUpper(); " +
                    @" b = strObj.Substring(15, 5).ToUpper(); " +
                    @" a + b ").
                Eval(dict);
相关问题