本文整理汇总了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;
}
示例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;
}
示例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;
}