本文整理汇总了C#中System.Linq.Expressions.InvocationExpression类的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpression类的具体用法?C# InvocationExpression怎么用?C# InvocationExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvocationExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了InvocationExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitInvocation
protected override Expression VisitInvocation(InvocationExpression iv)
{
if (iv.Expression is LambdaExpression)
return Visit(ExpressionReplacer.Replace(iv));
else
return base.VisitInvocation(iv); //Just calling a delegate in the projector
}
示例2: UpdateInvocation
protected InvocationExpression UpdateInvocation(InvocationExpression iv, Expression expression, IEnumerable<Expression> args)
{
if (args != iv.Arguments || expression != iv.Expression) {
return Expression.Invoke(expression, args);
}
return iv;
}
示例3: VisitInvocation
/// <summary>
/// Flatten calls to Invoke so that Entity Framework can understand it. Calls to Invoke are generated
/// by PredicateBuilder.
/// </summary>
protected override Expression VisitInvocation(InvocationExpression iv)
{
Expression target = iv.Expression;
if (target is MemberExpression) target = TransformExpr ((MemberExpression)target);
if (target is ConstantExpression) target = ((ConstantExpression)target).Value as Expression;
LambdaExpression lambda = (LambdaExpression)target;
Dictionary<ParameterExpression, Expression> replaceVars;
if (_replaceVars == null)
replaceVars = new Dictionary<ParameterExpression, Expression> ();
else
replaceVars = new Dictionary<ParameterExpression, Expression> (_replaceVars);
try
{
for (int i = 0; i < lambda.Parameters.Count; i++)
replaceVars.Add (lambda.Parameters[i], iv.Arguments[i]);
}
catch (ArgumentException ex)
{
throw new InvalidOperationException ("Invoke cannot be called recursively - try using a temporary variable.", ex);
}
return new ExpressionExpander (replaceVars).Visit (lambda.Body);
}
示例4: ParseInvocation
private ExpressionNode ParseInvocation(InvocationExpression ie)
{
var args = new List<LiteralNode>();
foreach(var arg in ie.Arguments)
{
if (arg is ParameterExpression)
{
var name = ((ParameterExpression)arg).Name;
args.Add(new VariableNode(name));
}
else if (arg is ConstantExpression)
{
var token = (String)((ConstantExpression)arg).Value;
args.Add(new ConstantNode(token));
}
else
{
return Unsupported(arg);
}
}
if (ie.Expression is MemberExpression)
{
var term = GetTermFromMemberExpression((MemberExpression)ie.Expression);
return new TermNode(term, args.ToArray());
}
return Unsupported(ie);
}
示例5: AssertInvokeIsOptimized
private static void AssertInvokeIsOptimized(InvocationExpression expr, Expression expression, IReadOnlyList<Expression> args)
{
var n = args.Count;
var updated = Update(expr);
var visited = Visit(expr);
foreach (var node in new[] { expr, updated, visited })
{
Assert.Same(expression, node.Expression);
AssertInvocation(n, node);
var argProvider = node as IArgumentProvider;
Assert.NotNull(argProvider);
Assert.Equal(n, argProvider.ArgumentCount);
if (node != visited) // our visitor clones argument nodes
{
for (var i = 0; i < n; i++)
{
Assert.Same(args[i], argProvider.GetArgument(i));
Assert.Same(args[i], node.Arguments[i]);
}
}
}
}
示例6: DoVisit
private void DoVisit(InvocationExpression invocation)
{
foreach (var arg in invocation.Arguments)
{
Visit(arg);
}
Visit(invocation.Expression);
}
示例7: VisitInvocation
protected override Expression VisitInvocation(InvocationExpression node)
{
if (typeof(Delegate).IsAssignableFrom(node.Expression.Type) || IsObservableFuncType(node.Expression.Type, node.Arguments.Count))
{
return VisitMethodCall(Expression.Call(node.Expression, node.Expression.Type.GetMethod("Invoke"), node.Arguments));
}
throw new InvalidOperationException("Unclear what to invoke.");
}
示例8: UpdateInvocation
protected static InvocationExpression UpdateInvocation(InvocationExpression node, Expression expression,
IEnumerable<Expression> args)
{
if (node.Arguments != args || node.Expression != expression)
{
return Expression.Invoke(expression, args);
}
return node;
}
示例9: InvocationExpectation
/// <summary>
/// Initializes a new instance of the <see cref="InvocationExpectation"/> class.
/// </summary>
/// <param name="lambdaExpression">The lambda expression.</param>
public InvocationExpectation(LambdaExpression lambdaExpression)
{
var expression = lambdaExpression.Body as InvocationExpression;
if (expression == null)
throw new ArgumentException("Invalid lambda expression", "lambdaExpression");
_expression = expression;
}
示例10: Replace
public static Expression Replace(InvocationExpression invocation)
{
LambdaExpression lambda = invocation.Expression as LambdaExpression;
var replacer = new ExpressionReplacer()
{
replacements = 0.To(lambda.Parameters.Count).ToDictionaryEx(i => lambda.Parameters[i], i => invocation.Arguments[i])
};
return replacer.Visit(lambda.Body);
}
示例11: VisitInvocation
protected override Expression VisitInvocation(InvocationExpression node)
{
var args = Visit(node.Arguments);
foreach(var arg in args)
AddParameter(arg);
var expr = Visit(node.Expression);
AddParameter(expr);
return null;
}
示例12: ParseInvokationExpression
private static ParsedCallExpression ParseInvokationExpression(InvocationExpression expression)
{
var target = Helpers.GetValueProducedByExpression(expression.Expression);
var method = target.GetType().GetMethod("Invoke");
return new ParsedCallExpression(
calledMethod: method,
callTargetExpression: expression.Expression,
argumentsExpressions: from argument in expression.Arguments.Zip(method.GetParameters(), (x, y) => new { Expression = x, ParameterInfo = y })
select new ParsedArgumentExpression(argument.Expression, argument.ParameterInfo));
}
示例13: VisitInvocation
protected override Expression VisitInvocation(InvocationExpression node)
{
ConstantExpression varNameExpr;
ParameterExpression contextExpr;
if ((contextExpr = node.Expression as ParameterExpression) != null &&
contextExpr.Name == _contextVarName &&
node.Arguments.Count == 1 &&
(varNameExpr = node.Arguments[0] as ConstantExpression) != null)
{
Variables.Add((string)varNameExpr.Value);
}
return base.VisitInvocation(node);
}
示例14: AutoInline
internal Expression AutoInline(InvocationExpression expression)
{
this.isLocked = true;
if (expression == null) throw new ArgumentNullException("expression");
var lambda = (LambdaExpression) expression.Expression;
var childScope = new ExpressionRewriter(this);
var lambdaParams = lambda.Parameters;
var invokeArgs = expression.Arguments;
if (lambdaParams.Count != invokeArgs.Count) throw new InvalidOperationException("Lambda/invoke mismatch");
for (int i = 0; i < lambdaParams.Count; i++)
{
childScope.Subst(lambdaParams[i], invokeArgs[i]);
}
return childScope.Apply(lambda.Body);
}
示例15: VisitInvocation
protected override Expression VisitInvocation(InvocationExpression node)
{
var baseResult = (InvocationExpression)base.VisitInvocation(node);
if (baseResult.Expression.NodeType == ExpressionType.Call)
{
var methodCallExpression = (MethodCallExpression)baseResult.Expression;
if (IsCompileMethod(methodCallExpression.Method))
{
Expression result;
if (TrySubstituteExpression(methodCallExpression.Object, baseResult.Arguments, out result))
return result;
}
}
return baseResult;
}