• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Expressions.MethodCallExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Linq.Expressions.MethodCallExpression的典型用法代码示例。如果您正苦于以下问题:C# MethodCallExpression类的具体用法?C# MethodCallExpression怎么用?C# MethodCallExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MethodCallExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了MethodCallExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Translate

        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("SUBSTR(");
            expressionTreeVisitor.VisitExpression(methodCallExpression.Object);
            expression.Append(", ");
            expressionTreeVisitor.VisitExpression(methodCallExpression.Arguments[0]);

            if (methodCallExpression.Arguments.Count > 1)
            {
                expression.Append(", ");
                expressionTreeVisitor.VisitExpression(methodCallExpression.Arguments[1]);
            }
            else if (methodCallExpression.Method.Name == "get_Chars")
            {
                // Called str[i], so return a single character at i
                expression.Append(", 1");
            }

            expression.Append(")");

            return methodCallExpression;
        }
开发者ID:amccool,项目名称:Linq2Couchbase,代码行数:29,代码来源:SubstringMethodCallTranslator.cs


示例2: AddParameterValuesFromExpressionToTempData

        // Copied this method from Microsoft.Web.Mvc.dll (MVC Futures)...
        // Microsoft.Web.Mvc.Internal.ExpresisonHelper.AddParameterValuesFromExpressionToDictionary().
        // The only change I made is saving the parameter values to TempData instead
        // of a RouteValueDictionary.
        private IDictionary<string, object> AddParameterValuesFromExpressionToTempData(TempDataDictionary tempData,
                                                                                       MethodCallExpression call)
        {
            ParameterInfo[] parameters = call.Method.GetParameters();
            var parsedParameters = new Dictionary<string, object>();

            if(parameters.Length > 0)
            {
                for(int i = 0; i < parameters.Length; i++)
                {
                    Expression expression = call.Arguments[i];
                    object obj2 = null;
                    ConstantExpression expression2 = expression as ConstantExpression;
                    if(expression2 != null)
                    {
                        obj2 = expression2.Value;
                    }
                    else
                    {
                        Expression<Func<object>> expression3 =
                            Expression.Lambda<Func<object>>(Expression.Convert(expression, typeof(object)),
                                                            new ParameterExpression[0]);
                        obj2 = expression3.Compile()();
                    }

                    tempData[RedirectParameterPrefix + parameters[i].Name] = obj2;
                    parsedParameters.Add(parameters[i].Name, obj2);
                }
            }

            return parsedParameters;
        }
开发者ID:hillsoul,项目名称:MvcContrib,代码行数:36,代码来源:PassParametersDuringRedirectAttribute.cs


示例3: ArrayAgg

        private static bool ArrayAgg(MethodCallExpression methodCall, StringBuilder queryBuilder, Action<Expression> visitExpression)
        {
            var typeName = GetTypeName(methodCall.Type);
            if (typeName == null)
                return false;
            var sqe = methodCall.Arguments[0] as SubQueryExpression;
            if (sqe != null)
            {
                var me = sqe.QueryModel.SelectClause.Selector as MemberExpression;
                queryBuilder.Append("(SELECT cast(collect(");
                if (me != null)
                    queryBuilder.Append('"').Append(me.Member.Name).Append('"');
                else //TODO detect supported selectors - only identity
                    visitExpression(sqe.QueryModel.SelectClause.Selector);
                queryBuilder.Append(')');
            }
            else queryBuilder.Append("SELECT cast(collect($sq) ");
            queryBuilder.Append(" AS ").Append(typeName).Append(") FROM ");
            if (methodCall.Arguments[0] is MemberExpression)
                queryBuilder.Append("TABLE(");
            else queryBuilder.Append('(');
            visitExpression(methodCall.Arguments[0]);
            queryBuilder.Append(") $sq)");

            return true;
        }
开发者ID:instant-hrvoje,项目名称:revenj,代码行数:26,代码来源:LinqMethods.cs


示例4: VisitMethodCall

        protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
        {
            Check.NotNull(methodCallExpression, nameof(methodCallExpression));

            if (methodCallExpression.Method.IsGenericMethod)
            {
                var methodInfo = methodCallExpression.Method.GetGenericMethodDefinition();

                if (ReferenceEquals(methodInfo, EntityQueryModelVisitor.PropertyMethodInfo))
                {
                    var newArg0 = Visit(methodCallExpression.Arguments[0]);

                    if (newArg0 != methodCallExpression.Arguments[0])
                    {
                        return Expression.Call(
                            methodCallExpression.Method,
                            newArg0,
                            methodCallExpression.Arguments[1]);
                    }

                    return methodCallExpression;
                }
            }

            return base.VisitMethodCall(methodCallExpression);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:26,代码来源:RelationalProjectionExpressionVisitor.cs


示例5: VisitMethodCall

        /// <summary>
        ///     Replaces calls to DbContext.Set() with an expression for the equivalent <see cref="ObjectQuery" />.
        /// </summary>
        /// <param name="node"> The node to replace. </param>
        /// <returns> A new node, which may have had the replacement made. </returns>
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            Check.NotNull(node, "node");

            // We are looking for either the generic or non-generic Set method on DbContext.
            // However, we don't constrain to this so if you write your own parameterless method on
            // a derived DbContext, then we will work with this as well.
            if (typeof(DbContext).IsAssignableFrom(node.Method.DeclaringType))
            {
                var memberExpression = node.Object as MemberExpression;
                if (memberExpression != null)
                {
                    // Only try to invoke the method if it is on the context, is not parameterless, and is not attributed
                    // as a function.
                    var context = GetContextFromConstantExpression(memberExpression.Expression, memberExpression.Member);
                    if (context != null
                        &&
                        !node.Method.GetCustomAttributes(typeof(DbFunctionAttribute), false).Any()
                        &&
                        node.Method.GetParameters().Length == 0)
                    {
                        var expression =
                            CreateObjectQueryConstant(
                                node.Method.Invoke(context, SetAccessBindingFlags, null, null, null));
                        if (expression != null)
                        {
                            return expression;
                        }
                    }
                }
            }

            return base.VisitMethodCall(node);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:39,代码来源:DbQueryVisitor.cs


示例6: Translate

        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("(");
            expressionTreeVisitor.VisitExpression(methodCallExpression.Object);
            expression.Append(" LIKE '%");

            var indexInsertStarted = expression.Length;

            expressionTreeVisitor.VisitExpression(methodCallExpression.Arguments[0]);

            var indexInsertEnded = expression.Length;

            expression.Append("%')");

            //Remove extra quote marks which have been added due to the string in the clause, these aren't needed as they have been added already in this case.
            expression.Remove(indexInsertStarted, 1);
            expression.Remove(indexInsertEnded - 2, 1);

            return methodCallExpression;
        }
开发者ID:amccool,项目名称:Linq2Couchbase,代码行数:27,代码来源:ContainsMethodCallTranslator.cs


示例7: Translate

        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var argument = methodCallExpression.Arguments[0];
            var methodCallArgument = argument as MethodCallExpression;

            if ((methodCallArgument != null) && SupportMethods.Contains(methodCallArgument.Method))
            {
                // Two method calls are reversing each other, so just skip them both

                return expressionTreeVisitor.VisitExpression(methodCallArgument.Arguments[0]);
            }

            var expression = expressionTreeVisitor.Expression;

            if (methodCallExpression.Method.Name == "FromDateTime")
            {
                expression.Append("STR_TO_MILLIS(");
            }
            else
            {
                expression.Append("MILLIS_TO_STR(");
            }

            expressionTreeVisitor.VisitExpression(argument);

            expression.Append(')');

            return methodCallExpression;
        }
开发者ID:amccool,项目名称:Linq2Couchbase,代码行数:34,代码来源:UnixMillisecondsMethodCallTranslator.cs


示例8: VisitMethodCall

        protected override QueryNode VisitMethodCall(MethodCallExpression methodCall)
        {
            MethodInfo method = methodCall.Method;
            if (method.DeclaringType == typeof (Queryable) || method.DeclaringType == typeof (QueryableExtensions))
                return base.VisitMethodCall(methodCall);

            // PATCH: this fixes querying on interfaces using indexers
            if (method.DeclaringType == ItemType || (method.DeclaringType != null && method.DeclaringType.IsAssignableFrom(ItemType)))
                return VisitItemMethod(methodCall);
            // END PATCH

            if (method.DeclaringType == typeof (string) || method.DeclaringType == typeof (MethodExtensions))
                return base.VisitMethodCall(methodCall);

            // PATCH: this fixes querying using ICollections on interfaces
            if (method.DeclaringType != null && method.DeclaringType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>)))
            {
                return VisitICollectionMethod(methodCall);
            }
            // END PATCH

            if (method.DeclaringType == typeof(Enumerable) && methodCall.Arguments.Count > 0 && methodCall.Arguments.First() is MemberExpression)
            {
                Type declaringType = ((MemberExpression)methodCall.Arguments.First()).Member.DeclaringType;

                // PATCH: fixes querying on interfaces using LINQ Enumerable extension methods
                if (declaringType == ItemType || (declaringType != null && declaringType.IsAssignableFrom(ItemType)))
                    return VisitLinqEnumerableExtensionMethod(methodCall);
            }

            return EvaluateMethodCall(methodCall);
        }
开发者ID:simonproctor,项目名称:Synthesis,代码行数:32,代码来源:BugFixExpressionParser.cs


示例9: Visit

 /// <summary>
 /// 访问指定的方法
 /// </summary>
 /// <param name="theEntityType">实体的类型</param>
 /// <param name="m">访问方法调用相关的表达式</param>
 /// <param name="tableAlias">表的别名</param>
 /// <param name="colConditionParts">存储条件节点的栈</param>
 /// <param name="colParameterNames">存储参数名称的列表</param>
 /// <param name="colDbTypes">存储数据库字段类型的列表</param>
 /// <param name="colArguments">存储条件值的列表</param>
 public static void Visit(Type theEntityType, MethodCallExpression m, string tableAlias, Stack<string> colConditionParts, List<string> colParameterNames, List<DbType> colDbTypes, List<object> colArguments)
 {
     if (m.Object is MemberExpression)
     {
         //类似n.Name.StartsWith("吴")这样的调用
         if (m.Object.Type == typeof(string))
         {
             StringMethodCallVisitor.Visit(theEntityType, m, tableAlias, colConditionParts, colParameterNames, colDbTypes, colArguments);
         }
         else
         {
             throw new Exception("暂不支持{" + m.ToString() + "}的调用!");
         }
     }
     else if (m.Object is ConstantExpression)
     {
         //类似"ABCD".Contains(n.Name)这样的调用
         var cons = m.Object as ConstantExpression;
         if (cons.Type == typeof(string))
         {
             StringMethodCallVisitor.Visit(theEntityType, m, tableAlias, colConditionParts, colParameterNames, colDbTypes, colArguments);
         }
         else
         {
             throw new Exception("暂不支持{" + m.ToString() + "}的调用!");
         }
     }
     else
     {
        throw new Exception("暂不支持{" + m.ToString() + "}的调用!");
     }
 }
开发者ID:dengxinqian,项目名称:stonefw_easyui,代码行数:42,代码来源:MethodCallVisitor.cs


示例10: VisitMethodCall

        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            Expression retExpr = null;

            if (node.Method.Name == _functionName)
            {
                var str = node.ToString();
                MethodCall call;
                if (_methodCalls.TryGetValue(str, out call))
                {
                    ++call.CallCount;
                }
                else
                {
                    call = new MethodCall(node, Expression.Parameter(node.Type, "param" + (_methodCalls.Count)));
                    _methodCalls.Add(str, call);
                }

                retExpr = call.Parameter;
            }
            else
                retExpr = base.VisitMethodCall(node);

            return retExpr;
        }
开发者ID:CosmicPirate,项目名称:ExpressionOptimization,代码行数:25,代码来源:ExpressionOptimizer.cs


示例11: ObjectDeserialiserQuerySink

        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectDeserialiserQuerySink"/> class.
        /// </summary>
        /// <param name="originalType">the original type that the query was made against.</param>
        /// <param name="instanceType">the type of the object that must be returned.</param>
        /// <param name="instanceName">Name of the instance (i.e the alias used in both the LINQ and SPARQL queries).</param>
        /// <param name="distinct">if set to <c>true</c> discard duplicate answers.</param>
        /// <param name="selectExpression">The select expression (derived from the the LINQ query). Used to help in deserialisation.</param>
        /// <param name="context">The data context that will monitor the objects created (not yet used).</param>
        public ObjectDeserialiserQuerySink(
            Type originalType,
            Type instanceType,
            string instanceName,
            bool distinct,
            MethodCallExpression selectExpression,
            RdfDataContext context)
        {
            #region Tracing

#line hidden
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug("Deserialising {0}.", instanceType.Name);
            }
#line default

            #endregion

            SelectExpression = selectExpression;
            this.originalType = originalType;
            this.instanceType = instanceType;
            InstanceName = instanceName;
            Distinct = distinct;
            DataContext = context;
            IncomingResults = new ArrayList();
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:36,代码来源:ObjectDeserialiser.cs


示例12: 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


示例13: VisitMethodCall

        internal override Expression VisitMethodCall(MethodCallExpression m)
        {
            Expression obj = this.Visit(m.Object);
            ReadOnlyCollection<Expression> args = this.VisitExpressionList(m.Arguments);

            // check for args changed
            if (obj != m.Object || args != m.Arguments)
            {
                MethodInfo mInfo = m.Method;
                Type[] typeArgs = (mInfo.IsGenericMethod) ? mInfo.GetGenericArguments() : null;

                if ((mInfo.IsStatic || mInfo.DeclaringType.IsAssignableFrom(obj.Type))
                    && ArgsMatch(mInfo, args, typeArgs))
                {
                    // current method is still valid
                    return Expression.Call(obj, mInfo, args);
                }
                else if (mInfo.DeclaringType == typeof(Queryable))
                {
                    // convert Queryable method to Enumerable method
                    MethodInfo seqMethod = FindEnumerableMethod(mInfo.Name, args, typeArgs);
                    args = this.FixupQuotedArgs(seqMethod, args);
                    return Expression.Call(obj, seqMethod, args);
                }
                else
                {
                    // rebind to new method
                    MethodInfo method = FindMethod(mInfo.DeclaringType, mInfo.Name, args, typeArgs);
                    args = this.FixupQuotedArgs(method, args);
                    return Expression.Call(obj, method, args);
                }
            }
            return m;
        }
开发者ID:rainersigwald,项目名称:corefx,代码行数:34,代码来源:EnumerableRewriter.cs


示例14: VisitMethodCallExpression

		protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
		{
			var method = expression.Method.IsGenericMethod
							 ? expression.Method.GetGenericMethodDefinition()
							 : expression.Method;

			if (_pagingMethods.Contains(method) && !_sessionFactory.Dialect.SupportsVariableLimit)
			{
				//TODO: find a way to make this code cleaner
				var query = VisitExpression(expression.Arguments[0]);
				var arg = expression.Arguments[1];

				if (query == expression.Arguments[0])
					return expression;

				return Expression.Call(null, expression.Method, query, arg);
			}

			if (VisitorUtil.IsDynamicComponentDictionaryGetter(expression, _sessionFactory))
			{
				return expression;
			}

			return base.VisitMethodCallExpression(expression);
		}
开发者ID:KaraokeStu,项目名称:nhibernate-core,代码行数:25,代码来源:ExpressionParameterVisitor.cs


示例15: CanHandle

		public override bool CanHandle(MethodCallExpression expression)
		{
			//////Contract.Assert(expression.Method != null);

			return expression.Method.DeclaringType == typeof(Math)
				   && expression.Method.Name == "Floor";
		}
开发者ID:GixEntertainment,项目名称:azure-mobile-services-for-unity3d,代码行数:7,代码来源:MathFloorMethodWriter.cs


示例16: VisitMethodCall

 protected override Expression VisitMethodCall(MethodCallExpression node)
 {
     return Expression.Call(
         Visit(node.Object),
         node.Method,
         node.Arguments.Select(n => Visit(n)));
 }
开发者ID:fedeneo77,项目名称:Handlebars.Net,代码行数:7,代码来源:PathBinder.cs


示例17: VisitMethodCall

		protected override Expression VisitMethodCall (MethodCallExpression methodCall)
		{
			if (IsQueryableExtension (methodCall.Method))
				return ReplaceQueryableMethod (methodCall);

			return base.VisitMethodCall (methodCall);
		}
开发者ID:runefs,项目名称:Marvin,代码行数:7,代码来源:QueryableTransformer.cs


示例18: RewriteIsMethod

        static Expression RewriteIsMethod(MethodCallExpression expression)
        {
            var argument = (ConstantExpression)expression.Arguments[0];
            var valueExpression = Expression.Constant(argument.Value);

            return Expression.Call(typeof(Arg), "Is", new[] { argument.Type }, valueExpression);
        }
开发者ID:rho24,项目名称:Machine.Fakes,代码行数:7,代码来源:NSubstituteExpressionRewriter.cs


示例19: VisitMethodCall

        private void VisitMethodCall(MethodCallExpression expression)
        {
            VisitExpression(expression.Object);
            string methodName = expression.Method.Name;
            object objToInvokeUpon = returnValueFromLastExpressionVisit;

            MethodInfo methodInfo = objToInvokeUpon.GetType().GetMethod(methodName,
                                                                        BindingFlags.Public | BindingFlags.Instance);
            int paramCount = methodInfo.GetParameters().Count();
            Array paramArray = Array.CreateInstance(typeof (Object), paramCount);

            for (int arrLocation = 0; arrLocation < expression.Arguments.Count; arrLocation++)
            {
                Expression argument = expression.Arguments[arrLocation];
                VisitExpression(argument);
                if (argument is ConstantExpression)
                {
                    object argValue = ((ConstantExpression) argument).Value;
                    paramArray.SetValue(argValue, arrLocation);
                }
                else
                {
                    object argValue = returnValueFromLastExpressionVisit;
                    paramArray.SetValue(argValue, arrLocation);
                    Console.WriteLine();
                }
            }
            var array = (object[]) paramArray;
            returnValueFromLastExpressionVisit = methodInfo.Invoke(objToInvokeUpon, array);
            if (returnValueFromLastExpressionVisit is Pattern)
            {
                m_pattern = (Pattern) returnValueFromLastExpressionVisit;
            }
        }
开发者ID:royosherove,项目名称:dotnet-linq-to-regex,代码行数:34,代码来源:PatternVisitor.cs


示例20: IsSupportedMethod

        /// <summary>
        /// Determines whether the expression represents a supported method call.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <remarks></remarks>
        public override BindingSignatureSupport IsSupportedMethod(MethodCallExpression expression)
        {
            switch (expression.Method.Name)
            {
                case "Equals":
                    return new BindingSignatureSupport(SignatureSupportType.SupportedAsFieldValue, ValuePredicateType.Equal);
                case "StartsWith":
                    return new BindingSignatureSupport(SignatureSupportType.SupportedAsFieldValue, ValuePredicateType.StartsWith);
                case "EndsWith":
                    return new BindingSignatureSupport(SignatureSupportType.SupportedAsFieldValue, ValuePredicateType.EndsWith);
                case "get_Item":
                    // This is the default accessor of a Dictionary, so check if the parent object is supported too
                    if (ExpressionHelper.IsMember(expression.Object) && IsSupportedMember(expression.Object as MemberExpression).SignatureSupportType != SignatureSupportType.NotSupported)
                        return new BindingSignatureSupport(SignatureSupportType.SupportedAsFieldName, ValuePredicateType.Equal);
                    break;
            }

            // Add support for dynamic expressions using an intermediary set of "fake" methods on DynamicMemberMetadata
            if (expression.Method == DynamicMemberMetadata.GetMemberMethod)
            {
                var firstArg = expression.Arguments[0] as ConstantExpression;
                if (firstArg != null)
                switch (firstArg.Value as string)
                {
                    case "NodeTypeAlias":
                    case "ContentTypeAlias":
                    case "MediaTypeAlias":
                        return new BindingSignatureSupport(SignatureSupportType.SupportedAsSchemaAlias, ValuePredicateType.Empty);
                }

                return new BindingSignatureSupport(SignatureSupportType.SupportedAsFieldName, ValuePredicateType.Empty);
            }

            return new BindingSignatureSupport(SignatureSupportType.SupportedAsFieldName, ValuePredicateType.Equal);
        }
开发者ID:Joebeazelman,项目名称:rebelcmsxu5,代码行数:40,代码来源:DefaultQueryStructureBinder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Expressions.NewArrayExpression类代码示例发布时间:2022-05-26
下一篇:
C# Expressions.MemberMemberBinding类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap