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


C# LambdaExpression.Compile方法代码示例

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


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

示例1: Lambda

        public Lambda(LambdaExpression lambdaExpression)
        {
            if (lambdaExpression == null)
                throw new ArgumentNullException("lambdaExpression");

            _lambdaExpression = lambdaExpression;
            _delegate = _lambdaExpression.Compile();
        }
开发者ID:kornarakis,项目名称:DynamicExpresso,代码行数:8,代码来源:Lambda.cs

示例2: ObjectOutputParameterExpression

 public ObjectOutputParameterExpression(LambdaExpression lambda, Type valueType, string alias)
     : base(ExpressionType, lambda.Type)
 {
     if (lambda.Parameters.Count != 2)
         throw Error.BadArgument("S0055: Lambda must have 2 arguments");
     setValueDelegate = lambda.Compile();
     Alias = alias;
     ValueType = valueType;
 }
开发者ID:TheRealDuckboy,项目名称:mono-soc-2008,代码行数:9,代码来源:ObjectOutputParameterExpression.cs

示例3: CalculateLabda

        public static Object CalculateLabda(LambdaExpression lambda, Object[] lambdaParams)
        {
            var compiledLambda = lambda.Compile();
            var invokeMethod = compiledLambda.GetType().GetMethod("Invoke");

            if (invokeMethod != null)
                return invokeMethod.Invoke(compiledLambda, lambdaParams);
            else
                throw new Exception();
        }
开发者ID:CosmicPirate,项目名称:ExpressionOptimization,代码行数:10,代码来源:Program.cs

示例4: ResultTransformer

 public ResultTransformer(LambdaExpression itemTransformation, LambdaExpression listTransformation)
 {
     if (itemTransformation != null)
     {
         _itemTransformation = itemTransformation.Compile();
     }
     if (listTransformation != null)
     {
         _listTransformation = listTransformation.Compile();
     }
 }
开发者ID:nkmajeti,项目名称:nhibernate,代码行数:11,代码来源:ResultTransformer.cs

示例5: DoCalculateLambda

        public static object DoCalculateLambda(LambdaExpression lambda,
                                               IDictionary<string, object> paramNameToValue)
        {
            IEnumerable<object> requiredParamValues;
            if (lambda.Parameters.Count == paramNameToValue.Count)
                requiredParamValues = paramNameToValue.Values;
            else
                requiredParamValues = from requiredParam in lambda.Parameters
                                      join allParam in paramNameToValue
                                        on requiredParam.Name equals allParam.Key
                                      select allParam.Value;

            return lambda.Compile().DynamicInvoke(requiredParamValues.ToArray());
        }
开发者ID:KasatkinaMariya,项目名称:LambdaReduction,代码行数:14,代码来源:CalculationUtils.cs

示例6: CheckInputCorrectness

        private static void CheckInputCorrectness(LambdaExpression lambda,
                                                  params object[] lambdaParams)
        {
            try
            {
                lambda.Compile();
            }
            catch (Exception originalException)
            {
                var message = string.Format("Lambda '{0}' is not compilable", lambda);
                throw new InvalidLambdaException(lambda,message,originalException);
            }

            TypeUtils.CheckParamValuesAreSuitableToLambda(lambda, lambdaParams);
        }
开发者ID:KasatkinaMariya,项目名称:LambdaReduction,代码行数:15,代码来源:FactoringOutAndCalculation.cs

示例7: Evaluate

        public static object Evaluate(LambdaExpression expression, object target)
        {
            if (target == null) return null;

            Delegate func = expression.Compile();

            object result = null;
            try
            {
                result = func.DynamicInvoke(target);
            }
            catch (Exception)
            {
                ;
            }

            return result;
        }
开发者ID:shawnewallace,项目名称:Griz,代码行数:18,代码来源:ExpressionHelper.cs

示例8: CompileLambda

        internal static Delegate/*!*/ CompileLambda(LambdaExpression/*!*/ lambda, bool debugMode, bool noAdaptiveCompilation) {
            if (debugMode) {
#if !SILVERLIGHT
                // try to use PDBs and fallback to CustomGenerator if not allowed to:
                if (_HasPdbPermissions) {
                    try {
                        return CompilerHelpers.CompileToMethod(lambda, DebugInfoGenerator.CreatePdbGenerator(), true);
                    } catch (SecurityException) {
                        // do not attempt next time in this app-domain:
                        _HasPdbPermissions = false;
                    }
                }
#endif
                return CompilerHelpers.CompileToMethod(lambda, new CustomGenerator(), false);
            } else if (noAdaptiveCompilation) {
                return lambda.Compile();
            } else {
                return lambda.LightCompile();
            }
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:20,代码来源:RubyScriptCode.cs

示例9: Parse

 private void Parse(LambdaExpression expression)
 {
     Value = expression.Compile().DynamicInvoke();
     Type valueType = Value.GetType();
     if (valueType.IsEntity())
     {
         Value = Engine.GetTable(valueType)
             .FindField(Field.BindedTo ?? Field.FieldName).GetValue(Value);
     }
 }
开发者ID:stalinvr007,项目名称:VoDB,代码行数:10,代码来源:ExpressionBodyParser.cs

示例10: VisitLambda

		protected override void VisitLambda (LambdaExpression lambda)
		{
			Push (lambda.Compile ());
		}
开发者ID:bvangrinsven,项目名称:db4o-net,代码行数:4,代码来源:ExpressionInterpreter.cs

示例11: EmitDynamicCallPreamble

        public static void EmitDynamicCallPreamble(DynamicExpression dyn, IPersistentMap spanMap, string methodName, Type returnType, List<ParameterExpression> paramExprs, Type[] paramTypes, CljILGen ilg, out LambdaExpression lambda, out Type delType, out MethodBuilder mbLambda)
        {
            Expression call = dyn;

            GenContext context = Compiler.CompilerContextVar.deref() as GenContext;
            if (context != null && context.DynInitHelper != null)
                call = context.DynInitHelper.ReduceDyn(dyn);

            if (returnType == typeof(void))
            {
                call = Expression.Block(call, Expression.Default(typeof(object)));
                returnType = typeof(object);
            }
            else if (returnType != call.Type)
            {
                call = Expression.Convert(call, returnType);
            }

            call = GenContext.AddDebugInfo(call, spanMap);

            delType = Microsoft.Scripting.Generation.Snippets.Shared.DefineDelegate("__interop__", returnType, paramTypes);
            lambda = Expression.Lambda(delType, call, paramExprs);
            mbLambda = null;

            if (context == null)
            {
                // light compile

                Delegate d = lambda.Compile();
                int key = RT.nextID();
                CacheDelegate(key, d);

                ilg.EmitInt(key);
                ilg.Emit(OpCodes.Call, Method_MethodExpr_GetDelegate);
                ilg.Emit(OpCodes.Castclass, delType);
            }
            else
            {
                mbLambda = context.TB.DefineMethod(methodName, MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, returnType, paramTypes);
                lambda.CompileToMethod(mbLambda);
            }
        }
开发者ID:chrisortman,项目名称:clojure-clr,代码行数:42,代码来源:MethodExpr.cs

示例12: Compile

 public Delegate Compile(LambdaExpression expression)
 {
     return expression.Compile();
 }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:4,代码来源:LambdaExpressionCompiler.cs

示例13: Run

        public object Run(LambdaExpression lambda, params object[] inline_parameter_values)
        {
            Delegate f = lambda.Compile();
            if (inline_parameter_values != null && inline_parameter_values.Length > 0)
                return f.DynamicInvoke(inline_parameter_values);

            List<object> parameterList = new List<object>();
            if (lambda.Parameters != null && lambda.Parameters.Count > 0)
            {
                foreach (ParameterExpression pe in lambda.Parameters)
                {
                    if (this.ParameterValue.ContainsKey(pe.Name))
                        parameterList.Add(this.ParameterValue[pe.Name]);
                    else if (GlobalParameterValue.ContainsKey(pe.Name))
                        parameterList.Add(GlobalParameterValue[pe.Name]);
                    else
                        throw new ExprException(string.Format("The value for {0} is undefined.", pe.Name));
                }
            }
            return f.DynamicInvoke(parameterList.ToArray());
        }
开发者ID:tiger2soft,项目名称:DotNet.Utilities,代码行数:21,代码来源:ExprParser.cs

示例14: DecodedExpression

 public DecodedExpression(LambdaExpression expression)
 {
     _expression = expression;
     _delegate = _expression.Compile();
 }
开发者ID:mcwatt77,项目名称:vimcontrols,代码行数:5,代码来源:DecodedExpression.cs

示例15: CompileLambda

        private Delegate CompileLambda(LambdaExpression code, EventHandler<LightLambdaCompileEventArgs> handler)
        {
            if (_lambda.ShouldInterpret)
            {
                Delegate result = CompilerHelpers.LightCompile(code, _lambda.GlobalParent.TotemContext.Options.CompilationThreshold);

                // If the adaptive compiler decides to compile this function, we
                // want to store the new compiled target. This saves us from going
                // through the interpreter stub every call.
                var lightLambda = result.Target as LightLambda;
                if (lightLambda != null)
                {
                    lightLambda.Compile += handler;
                }

                return result;
            }

            return code.Compile();
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:20,代码来源:FunctionCode.cs


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