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


C# Expression.Compile方法代码示例

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


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

示例1: CompileCheck

        public static void CompileCheck(FunctionContext context, Expression expression, int requiredStack)
        {
            var stack = expression.Compile(context);

            if (stack != requiredStack)
                throw new MondCompilerException(expression.FileName, expression.Line, "Bad stack state");
        }
开发者ID:krixalis,项目名称:Mond,代码行数:7,代码来源:Expression.cs

示例2: That

 public static void That(Expression<Func<bool>> assertion, string msg = null)
 {
     var compiled = assertion.Compile();
     bool? ok;
     try {
         ok = compiled();
     } catch (Exception e) {
         msg = MergeExceptionMessages(ExpressionToCode.AnnotatedToCode(assertion.Body), msg, e);
         throw UnitTestingFailure.AssertionExceptionFactory(msg, e);
     }
     if (ok == false) {
         msg = MergeExceptionMessages(ExpressionToCode.AnnotatedToCode(assertion.Body), msg);
         throw UnitTestingFailure.AssertionExceptionFactory(msg, null);
     }
 }
开发者ID:rameshbolla,项目名称:ExpressionToCode,代码行数:15,代码来源:PAssert.cs

示例3: F

 public static int F(Expression<Func<int>> f)
 {
     return f.Compile()();
 }
开发者ID:GeneralRookie,项目名称:corefx,代码行数:4,代码来源:ExpressionCatalog.Unary.cs

示例4: ExecuteIfNotInEditor

 public static void ExecuteIfNotInEditor(Expression<Action> attempt, Action alternate = null)
 {
     try
     {
         if (!Application.isEditor)
         {
             attempt.Compile()();
         }
         else
         {
             Debug.Log("Execution requested of: " + attempt.Body);
             if (alternate != null)
                 alternate();
         }
     }
     catch (Exception e)
     {
         LogHandler.Handle(e);
     }
 }
开发者ID:Trifectgaming,项目名称:EdgeOnlineChallenge,代码行数:20,代码来源:AdManager.cs

示例5: Expression

 /// <summary>
 /// Used to create: {ValueLeft}{ComparisonOperator}{ValueRight}
 /// Used to create: {UnaryOperation}{Value}
 /// Used to create: {Value[0]}{BinaryOperator}{Value[1]}...{Value[n]}
 /// </summary>
 public Expression(Expression<Func<string>> operationExpression)
 {
     Func<string> deleg = operationExpression.Compile();
     this.Value = deleg();
 }
开发者ID:ricardocarneiro,项目名称:sharepoint-3,代码行数:10,代码来源:Expression.cs

示例6: CompileBody

        private Func<CodeContext, FunctionCode, object> CompileBody(Expression<Func<CodeContext/*!*/, FunctionCode/*!*/, object>> lambda) {
            Func<CodeContext, FunctionCode, object> func;
            PythonContext pc = (PythonContext)Ast.CompilerContext.SourceUnit.LanguageContext;

            if (lambda.Body is ConstantExpression) {
                // skip compiling for really simple code
                object value = ((ConstantExpression)lambda.Body).Value;
                return (codeCtx, functionCode) => value;
            }

            if (pc.ShouldInterpret((PythonCompilerOptions)Ast.CompilerContext.Options, Ast.CompilerContext.SourceUnit)) {
                func = CompilerHelpers.LightCompile(lambda, false, pc.Options.CompilationThreshold);
            } else {
                func = lambda.Compile(Ast.CompilerContext.SourceUnit.EmitDebugSymbols);
            }

            return func;
        }
开发者ID:mstram,项目名称:ironruby,代码行数:18,代码来源:PythonScriptCode.cs

示例7: DoNotLogMessageIfTraceDisabled

            public void DoNotLogMessageIfTraceDisabled(Expression<Action<ILog>> expression, String expectedMessage)
            {
                var logger = new Logger("MyTestLogger", SourceLevels.Off);
                var listener = new FakeTraceListener();
                var testMethod = expression.Compile();

                logger.TraceSource.Listeners.Add(listener);

                testMethod(logger);

                Assert.Equal(0, listener.Messages.Count(m => m == expectedMessage));
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:12,代码来源:LoggerTests.cs

示例8: LogMessageIfTraceEnabled

            public void LogMessageIfTraceEnabled(Expression<Action<ILog>> expression, String expectedMessage)
            {
                var logger = new Logger("MyTestLogger", SourceLevels.All);
                var testMethod = expression.Compile();

                lock (FakeTraceListener.Instance)
                {
                    Trace.Listeners.Add(FakeTraceListener.Instance);

                    try
                    {
                        testMethod(logger);

                        Assert.Equal(1, FakeTraceListener.Instance.Messages.Count(m => m == "MyTestLogger: " + expectedMessage));
                    }
                    finally
                    {
                        Trace.Listeners.Remove(FakeTraceListener.Instance);
                        FakeTraceListener.Instance.Clear();
                    }
                }
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:22,代码来源:LoggerTests.cs


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