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


C# MethodCallExpression.Update方法代码示例

本文整理汇总了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);
        }
开发者ID:david0718,项目名称:LinqCache,代码行数:35,代码来源:LocalCollectionExpander.cs

示例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;
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:31,代码来源:SubQueryMemberPushDownExpressionVisitor.cs

示例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);
		}
开发者ID:s-KaiNet,项目名称:Untech.SharePoint,代码行数:17,代码来源:BoolEqualityModifier.cs

示例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);
		}
开发者ID:s-KaiNet,项目名称:Untech.SharePoint,代码行数:23,代码来源:WhereModifier.cs

示例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);
        }
开发者ID:pirrmann,项目名称:LinqToService,代码行数:24,代码来源:SearchCriteriaBuilder.cs

示例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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:CallFactoryTests.cs

示例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));
        }
开发者ID:RossMerr,项目名称:CouchbaseNetClient,代码行数:8,代码来源:LambdaSimplifyingExpressionVisitor.cs


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