本文整理汇总了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();
}
示例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;
}
示例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();
}
示例4: ResultTransformer
public ResultTransformer(LambdaExpression itemTransformation, LambdaExpression listTransformation)
{
if (itemTransformation != null)
{
_itemTransformation = itemTransformation.Compile();
}
if (listTransformation != null)
{
_listTransformation = listTransformation.Compile();
}
}
示例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());
}
示例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);
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例10: VisitLambda
protected override void VisitLambda (LambdaExpression lambda)
{
Push (lambda.Compile ());
}
示例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);
}
}
示例12: Compile
public Delegate Compile(LambdaExpression expression)
{
return expression.Compile();
}
示例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());
}
示例14: DecodedExpression
public DecodedExpression(LambdaExpression expression)
{
_expression = expression;
_delegate = _expression.Compile();
}
示例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();
}