当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionContext.CompileDynamic方法代码示例

本文整理汇总了C#中ExpressionContext.CompileDynamic方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionContext.CompileDynamic方法的具体用法?C# ExpressionContext.CompileDynamic怎么用?C# ExpressionContext.CompileDynamic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExpressionContext的用法示例。


在下文中一共展示了ExpressionContext.CompileDynamic方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile

 public void Compile(ExpressionContext context)
 {
     // TODO: verify wheather the expression is a value (no need to compile)
     bool isValue = false;
     if (!isValue)
         eDynamic = context.CompileDynamic(AssignmentExpression);
 }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:7,代码来源:Assignment.cs

示例2: Test

        private static void Test(IQuestion qs)
        {
            Console.WriteLine(qs.Question);

            var q = qs.Question;
            q = q.Replace("pluss", "+").
                Replace("minus", "-").
                Replace("ganger", "*").
                Replace("delt på", "/").
                Replace("Hva er", "");
            Console.WriteLine(q);
            var context = new ExpressionContext();
            context.Imports.AddType(typeof (Math));
            var eDynamic = context.CompileDynamic(q);
            var res = eDynamic.Evaluate();
            Assert.IsTrue(qs.Run("" + res));
        }
开发者ID:eirikb,项目名称:extreme-sharepoint,代码行数:17,代码来源:CalculusTest.cs

示例3: GetReferencedVariables

        public static string[] GetReferencedVariables(string expression, string[] variables)
        {
            if (String.IsNullOrWhiteSpace(expression))
                return null;
            if ((variables == null) ||(variables.Length < 1))
                return null;

            ExpressionContext context = new ExpressionContext();
            // Use string.format
            context.Imports.AddType(typeof(string));
            //context.Imports.AddType(typeof(CustomFunctions));

            for (int i=0;i<variables.Length;i++)
                context.Variables[variables[i]] = 1.0;

            IDynamicExpression e = context.CompileDynamic(expression);
            return e.Info.GetReferencedVariables();
        }
开发者ID:wrbrooks,项目名称:VB3,代码行数:18,代码来源:ExpressionEvaluator.cs

示例4: Main

        public static void Main()
        {
            ExpressionContext context = new ExpressionContext();
            context.Options.EmitToAssembly = true;

            //context.ParserOptions.RequireDigitsBeforeDecimalPoint = True
            //context.ParserOptions.DecimalSeparator = ","c
            //context.ParserOptions.RecreateParser()
            //context.Options.ResultType = GetType(Decimal)

            context.Variables["a"] = 2;
            context.Variables["b"] = 4;

            IDynamicExpression e1 = context.CompileDynamic("If (19 in (13,28,33,48,71,73,101,102,103,104,23,23,234,34,345,345,45,34,34,4555,445,20),1,0)");
            var res1 = e1.Evaluate();

            var e = context.CompileGeneric<bool>("b > a");
            object result = e.Evaluate();

            Console.ReadLine();
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:21,代码来源:Program.cs

示例5: Evaluate

        //public List<double> Evaluate(string expression, DataTable dt)
        public DataTable Evaluate(string expression, DataTable dt)
        {
            List<double> lstCalcValues = new List<double>();
            DataTable dtCalcValues = new DataTable();
            dtCalcValues.Columns.Add("ID", typeof(string));
            dtCalcValues.Columns.Add("CalcValue", typeof(double));

            MyTable = dt;

            ExpressionContext context = new ExpressionContext();
            // Use string.format
            context.Imports.AddType(typeof(string));

            // Use on demand variables to provide the values for the columns
            context.Variables.ResolveVariableType += new EventHandler<ResolveVariableTypeEventArgs>(Variables_ResolveVariableType);
            context.Variables.ResolveVariableValue += new EventHandler<ResolveVariableValueEventArgs>(Variables_ResolveVariableValue);

            // Create the expression; Flee will now query for the types of ItemName, Price, and Tax
            IDynamicExpression e = context.CompileDynamic(expression);

            Console.WriteLine("Computing value of '{0}' for all rows", e.Text);

            DataRow dr = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MyCurrentRow = dt.Rows[i];
                // Evaluate the expression; Flee will query for the values of the columns
                double dlbResult = (double) e.Evaluate();
                lstCalcValues.Add(dlbResult);

                dr = dtCalcValues.NewRow();
                dr[0] = MyCurrentRow[0] as string;
                dr[1] = dlbResult;
                dtCalcValues.Rows.Add(dr);
                Console.WriteLine("Row {0} = {1}", i, dlbResult);
            }
            return dtCalcValues;
        }
开发者ID:wrbrooks,项目名称:VB3,代码行数:39,代码来源:ExpressionEvaluator.cs

示例6: CreateExpressionEvaluator

        private Func<double, double> CreateExpressionEvaluator(string expression)
        {
            ExpressionContext context = new ExpressionContext();
            context.Options.EmitToAssembly = false;
            context.Imports.AddType(typeof(Math));

            context.Variables["x"] = 0.0d;

            IDynamicExpression fx = null;

            try
            {
                fx = context.CompileDynamic(expression);
            }
            catch (ExpressionCompileException)
            {
                return null;
            }

            Func<Double, Double> expressionEvaluator = (Double i) =>
            {
                context.Variables["x"] = i;
                return (Double)fx.Evaluate();
            };

            return expressionEvaluator;
        }
开发者ID:brainx64,项目名称:ChartBuilderService,代码行数:27,代码来源:ChartBuilderService.svc.cs

示例7: C

        public C(int times)
        {
            var r = new Random();
            var context = new ExpressionContext();
            context.Imports.AddType(typeof (Math));
            var c = 0;
            var qs = Enumerable.Range(0, times).ToList().Select(i =>
                {
                    var type = _types.Keys.ToList()[r.Next(_types.Count)];
                    c++;
                    var v = "a" + c;
                    context.Variables[v] = r.Next(-2000, 10000);
                    return string.Format("{0} {1}", v, type);
                });
            Q = string.Join(" ", qs.ToArray()).Trim();
            Q = Q.Substring(0, Q.Length - 1);
            var eDynamic = context.CompileDynamic(Q);

            Res = (int) eDynamic.Evaluate();
            Console.WriteLine(Q + " = " + Res);

            _types.ToList().ForEach(type => Q = Q.Replace(type.Key, type.Value));
            context.Variables.Keys.ToList().ForEach(key => Q = Q.Replace(key, "" + context.Variables[key]));
        }
开发者ID:eirikb,项目名称:extreme-sharepoint,代码行数:24,代码来源:Calculus.cs

示例8: ExpressionEvaluationTest

        public void ExpressionEvaluationTest()
        {
            ExpressionContext context = new ExpressionContext();
            context.Variables.Add("rand", new Random());

            IDynamicExpression e = context.CompileDynamic("rand.nextDouble() + 100");
            double result = (double)e.Evaluate();

            //no LINQ
            //var doc = new XDocument(new XElement("test", 
            //    new XElement("val", "result1"),
            //    new XElement("val", "result2"),
            //    new XElement("val", "result3")
            //    ));
            //context.Variables.Add("doc", doc);

            //e = context.CompileDynamic("doc.Elements().First().Value");
            //var r = e.Evaluate();

            //no Dynamic
            //dynamic expando = new ExpandoObject();
            //expando.test = "Passed";
            //context.Variables.Add("expando", expando);
            //e = context.CompileDynamic("expando.test");
            //var r = e.Evaluate();

        }
开发者ID:ikutsin,项目名称:BinaryAnalysis.Core,代码行数:27,代码来源:RedistTests.cs

示例9: CreateExpression

 private IDynamicExpression CreateExpression(string expression, ExpressionContext context)
 {
     return context.CompileDynamic(expression);
 }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:4,代码来源:CalcEngineTestFixture.cs

示例10: Compile

 public void Compile(ExpressionContext context)
 {
     if (_expression != string.Empty && _expression != "true" && _expression != "false")
         eDynamic = context.CompileDynamic(_expression);
 }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:5,代码来源:Inequation.cs

示例11: TestNoStateHeldInContext

        public void TestNoStateHeldInContext()
        {
            ExpressionContext context = new ExpressionContext();

            IGenericExpression<int> e1 = context.CompileGeneric<int>("300");

            // The result type of the cloned context should be set to integer
            Assert.IsTrue(object.ReferenceEquals(e1.Context.Options.ResultType, typeof(Int32)));

            // The original context should not be affected
            Assert.IsNull(context.Options.ResultType);

            // This should compile
            IDynamicExpression e2 = context.CompileDynamic("\"abc\"");
            Assert.IsTrue(object.ReferenceEquals(e2.Context.Options.ResultType, typeof(string)));

            // The original context should not be affected
            Assert.IsNull(context.Options.ResultType);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:19,代码来源:IndividualTests.cs


注:本文中的ExpressionContext.CompileDynamic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。