Empeld
Empeld plugin documentation.
pluginbase.Helpers.Extensions.ExpressionExtensions Class Reference

Expression extension methods More...

Classes

class  CallableExpression
 

Static Public Member Functions

static CallableExpression ReduceMethodCall (this LambdaExpression exp)
 Reduces a method call to its info, and values for arguments More...
 
static object Evaluate (this Expression exp, bool reflective=true)
 Evaluate the value of an expression More...
 

Detailed Description

Expression extension methods

Member Function Documentation

◆ Evaluate()

static object pluginbase.Helpers.Extensions.ExpressionExtensions.Evaluate ( this Expression  exp,
bool  reflective = true 
)
static

Evaluate the value of an expression

Parameters
expThe expression
reflectiveIf set to true use reflective. Usually faster.
55  {
56  if (reflective)
57  {
58  return EvaluateReflective(exp);
59  }
60  return Expression.Lambda(exp).Compile().DynamicInvoke();
61  }

◆ ReduceMethodCall()

static CallableExpression pluginbase.Helpers.Extensions.ExpressionExtensions.ReduceMethodCall ( this LambdaExpression  exp)
static

Reduces a method call to its info, and values for arguments

Returns
The method call.
Parameters
expExp.

Attribute: method.Arguments.Count

;

Attribute: i] = method.Arguments[i

.Evaluate();

27  {
28  var method = exp.Body as MethodCallExpression;
29  if (method == null)
30  {
31  throw new InvalidOperationException("Expected expression to be callable");
32  }
33 
34  var args = new object[method.Arguments.Count];
35  for (int i=0; i<args.Length; ++i)
36  {
37  args[i] = method.Arguments[i].Evaluate();
38  }
39 
40  return new CallableExpression
41  {
42  ArgumentValues = args,
43  Method = method.Method,
44  TargetType = EvaluateType(method.Object)
45  };
46  }

The documentation for this class was generated from the following file: