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


C# MethodCallExpression.Evaluate方法代码示例

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


在下文中一共展示了MethodCallExpression.Evaluate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitStringQxMethodCall

        protected virtual Expression VisitStringQxMethodCall(MethodCallExpression e)
        {
            var member = e.GetRightMostMember();

            var expressionIsNotForMember = member == null || member.Expression.NodeType == ExpressionType.Constant;
            if (expressionIsNotForMember)
                return Visit(Expression.Constant(e.Evaluate()));

            var methodName = e.Method.Name;

            switch (methodName)
            {
                case "QxContains":
                    Nodes.AddNode(CreateNewMemberNode(member).ToStringContainsNode(e.Arguments[1].Evaluate().ToStringOrNull()));
                    break;
                case "QxStartsWith":
                    Nodes.AddNode(CreateNewMemberNode(member).ToStringStartsWithNode(e.Arguments[1].Evaluate().ToStringOrNull()));
                    break;
                case "QxEndsWith":
                    Nodes.AddNode(CreateNewMemberNode(member).ToStringEndsWithNode(e.Arguments[1].Evaluate().ToStringOrNull()));
                    break;
                case "QxIsExactly":
                    Nodes.AddNode(CreateNewMemberNode(member).ToStringExactNode(e.Arguments[1].Evaluate().ToStringOrNull()));
                    break;
                case "QxLike":
                    Nodes.AddNode(CreateNewMemberNode(member).ToLikeNode(e.Arguments[1].Evaluate().ToStringOrNull()));
                    break;
                case "QxToLower":
                    Nodes.AddNode(CreateNewMemberNode(member).ToLowerNode());
                    break;
                case "QxToUpper":
                    Nodes.AddNode(CreateNewMemberNode(member).ToUpperNode());
                    break;
                default:
                    throw new SisoDbNotSupportedException("String query extension (Qx) method '{0}', is not supported.".Inject(methodName));
            }

            return e;
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:39,代码来源:WhereParser.cs

示例2: VisitMethodCall

        protected override Expression VisitMethodCall(MethodCallExpression e)
        {
            if (e.Method.DeclaringType == typeof(StringQueryExtensions))
                return VisitStringQxMethodCall(e);

            if (e.Method.DeclaringType == typeof(string))
                return VisitStringMethodCall(e);
            
            if (e.Method.DeclaringType == typeof(EnumerableQueryExtensions))
                return VisitEnumerableQxMethodCall(e);

            try
            {
                var value = e.Evaluate();
                var constant = Expression.Constant(value);
                Visit(constant);
            }
            catch (Exception ex)
            {
                throw new NotSupportedException(
                    ExceptionMessages.LambdaParser_UnsupportedMethodCall.Inject(e.ToString()), ex);
            }

            return e;
        }
开发者ID:BlackMael,项目名称:SisoDb-Provider,代码行数:25,代码来源:WhereParser.cs

示例3: VisitStringMethodCall

        protected virtual Expression VisitStringMethodCall(MethodCallExpression e)
        {
            var member = e.GetRightMostMember();

            var expressionIsNotForMember = member == null || member.Expression.NodeType == ExpressionType.Constant;
            if (expressionIsNotForMember)
                return Visit(Expression.Constant(e.Evaluate()));

            var methodName = e.Method.Name;
            switch (methodName)
            {
                case "Contains":
                    Nodes.AddNode(CreateNewMemberNode(member).ToStringContainsNode(e.Arguments[0].Evaluate().ToStringOrNull()));
                    break;
                case "StartsWith":
                    Nodes.AddNode(CreateNewMemberNode(member).ToStringStartsWithNode(e.Arguments[0].Evaluate().ToStringOrNull()));
                    break;
                case "EndsWith":
                    Nodes.AddNode(CreateNewMemberNode(member).ToStringEndsWithNode(e.Arguments[0].Evaluate().ToStringOrNull()));
                    break;
                case "ToLower":
                    Nodes.AddNode(CreateNewMemberNode(member).ToLowerNode());
                    break;
                case "ToUpper":
                    Nodes.AddNode(CreateNewMemberNode(member).ToUpperNode());
                    break;
            }

            return e;
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:30,代码来源:WhereParser.cs


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