本文整理汇总了C#中System.Linq.Expressions.MethodCallExpression.Update方法的典型用法代码示例。如果您正苦于以下问题:C# MethodCallExpression.Update方法的具体用法?C# MethodCallExpression.Update怎么用?C# MethodCallExpression.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.Update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
var instanceType = node.Object == null ? null : node.Object.Type;
var map = new[] { new { Param = instanceType, Arg = node.Object } }.ToList();
map.AddRange(node.Method.GetParameters()
.Zip(node.Arguments, (p, a) => new { Param = p.ParameterType, Arg = a }));
// for any local collection parameters in the method, make a
// replacement argument which will print its elements
var replacements = (map.Where(x => x.Param != null && x.Param.IsGenericType)
.Select(x => new {x, g = x.Param.GetGenericTypeDefinition()})
.Where(@t => @t.g == typeof (IEnumerable<>) || @t.g == typeof (List<>))
.Where(@t => @t.x.Arg.NodeType == ExpressionType.Constant)
.Select(@t => new {@t, elementType = @t.x.Param.GetGenericArguments().Single()})
.Select(
@t =>
new
{
@[email protected],
Replacement =
Expression.Constant("{" + string.Join("|", (IEnumerable) ((ConstantExpression) @[email protected]).Value) + "}")
})).ToList();
if (replacements.Any())
{
var args = map.Select(x => (from r in replacements
where r.Arg == x.Arg
select r.Replacement).SingleOrDefault() ?? x.Arg).ToList();
node = node.Update(args.First(), args.Skip(1));
}
return base.VisitMethodCall(node);
}
示例2: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
{
var newMethodCallExpression = (MethodCallExpression)base.VisitMethodCall(methodCallExpression);
if (EntityQueryModelVisitor.IsPropertyMethod(methodCallExpression.Method))
{
var subQueryExpression = newMethodCallExpression.Arguments[0] as SubQueryExpression;
var subSelector = subQueryExpression?.QueryModel.SelectClause.Selector as QuerySourceReferenceExpression;
if (subSelector != null)
{
var subQueryModel = subQueryExpression.QueryModel;
subQueryModel.SelectClause.Selector
= methodCallExpression
.Update(
null,
new[]
{
subSelector,
methodCallExpression.Arguments[1]
});
subQueryModel.ResultTypeOverride = subQueryModel.SelectClause.Selector.Type;
return new SubQueryExpression(subQueryModel);
}
}
return newMethodCallExpression;
}
示例3: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
if (node.Method.Name == "Where")
{
var lambda = (LambdaExpression)node.Arguments[1].StripQuotes();
var predicate = lambda.Body.StripQuotes();
if (CanMakeEqualTrueFalse(predicate))
{
var newLambda = Expression.Lambda(MakeEqualTrueFalse(predicate), lambda.Parameters);
return base.VisitMethodCall(node.Update(null, new[] { node.Arguments[0], newLambda }));
}
}
return base.VisitMethodCall(node);
}
示例4: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
if (node.Method.Name == "Where")
{
var innerMethodCall = node.Arguments[0] as MethodCallExpression;
if (innerMethodCall != null && innerMethodCall.Method.Name == "Where")
{
var currentLambda = (LambdaExpression)node.Arguments[1].StripQuotes();
var innerLambda = (LambdaExpression)innerMethodCall.Arguments[1].StripQuotes();
if (currentLambda.Type != innerLambda.Type)
{
throw new NotSupportedException("Where methods have predicates with mismatch return type or arguments list");
}
var newCondition = Expression.AndAlso(innerLambda.Body, currentLambda.Body);
var newLambda = Expression.Lambda(newCondition, currentLambda.Parameters);
return Visit(node.Update(null, new[] { innerMethodCall.Arguments[0], newLambda }));
}
}
return base.VisitMethodCall(node);
}
示例5: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
if (node.Method.Name == "Take")
{
this.criteria = new SearchCriteria();
}
else if (node.Method.Name == "Where")
{
Type[] genericArguments = node.Method.GetGenericArguments();
if (genericArguments.Length == 1 && genericArguments[0] == typeof(Person))
{
return node.Update(
node.Object,
new Expression[]
{
Visit(node.Arguments[0]),
Expression.Quote(VisitWhereClause((LambdaExpression)((UnaryExpression)(node.Arguments[1])).Operand))
});
}
}
return base.VisitMethodCall(node);
}
示例6: Update
private static MethodCallExpression Update(MethodCallExpression node)
{
// Tests the call of Update to Expression.Call factories.
var res = node.Update(node.Object, node.Arguments.ToArray());
Assert.NotSame(node, res);
return res;
}
示例7: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
var children = new[] {node.Object}.Concat(node.Arguments).ToList();
VisitChildren(children);
return node.Update(children[0], children.Skip(1));
}