本文整理汇总了C#中System.Linq.Expressions.LambdaExpression.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LambdaExpression.ToString方法的具体用法?C# LambdaExpression.ToString怎么用?C# LambdaExpression.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.LambdaExpression
的用法示例。
在下文中一共展示了LambdaExpression.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LambdaExpressionCacheKey
public LambdaExpressionCacheKey(LambdaExpression obj)
{
ReturnType = obj.ReturnType.FullName;
ExpressionAsString = obj.ToString();
ArgTypes = new HashSet<string>(obj.Parameters.Select(x => x.Type.FullName));
_toString = null;
}
示例2: FilterPredicate
public FilterPredicate(LambdaExpression lambda)
{
Util.Check(lambda.Parameters.Count > 0, "Invalid FilterPredicate lambda - must have at least one Entity parameter.");
Util.Check(lambda.Body.Type == typeof(bool), "Invalid FilterPredicate lambda - must have bool return type.");
Lambda = lambda;
EntityType = Lambda.Parameters[0].Type;
_asString = lambda.ToString();
}
示例3: ValidateOpAssignConversionLambda
private static void ValidateOpAssignConversionLambda(LambdaExpression conversion, Expression left, MethodInfo method, ExpressionType nodeType)
{
Type delegateType = conversion.Type;
Debug.Assert(typeof(System.MulticastDelegate).IsAssignableFrom(delegateType) && delegateType != typeof(System.MulticastDelegate));
MethodInfo mi = delegateType.GetMethod("Invoke");
ParameterInfo[] pms = mi.GetParametersCached();
Debug.Assert(pms.Length == conversion.Parameters.Count);
if (pms.Length != 1)
{
throw Error.IncorrectNumberOfMethodCallArguments(conversion);
}
if (!TypeUtils.AreEquivalent(mi.ReturnType, left.Type))
{
throw Error.OperandTypesDoNotMatchParameters(nodeType, conversion.ToString());
}
if (method != null)
{
// The parameter type of conversion lambda must be the same as the return type of the overload method
if (!TypeUtils.AreEquivalent(pms[0].ParameterType, method.ReturnType))
{
throw Error.OverloadOperatorTypeDoesNotMatchConversionType(nodeType, conversion.ToString());
}
}
}
示例4: Coalesce
/// <summary>
/// Creates a BinaryExpression that represents a coalescing operation.
/// </summary>
/// <param name="left">An <see cref="Expression"/> to set the <see cref="P:BinaryExpression.Left"/> property equal to.</param>
/// <param name="right">An <see cref="Expression"/> to set the <see cref="P:BinaryExpression.Right"/> property equal to.</param>
/// <param name="conversion">A LambdaExpression to set the Conversion property equal to.</param>
/// <returns>A BinaryExpression that has the NodeType property equal to Coalesce and the Left, Right and Conversion properties set to the specified values.
/// </returns>
public static BinaryExpression Coalesce(Expression left, Expression right, LambdaExpression conversion)
{
RequiresCanRead(left, nameof(left));
RequiresCanRead(right, nameof(right));
if (conversion == null)
{
Type resultType = ValidateCoalesceArgTypes(left.Type, right.Type);
return new SimpleBinaryExpression(ExpressionType.Coalesce, left, right, resultType);
}
if (left.Type.GetTypeInfo().IsValueType && !TypeUtils.IsNullableType(left.Type))
{
throw Error.CoalesceUsedOnNonNullType();
}
Type delegateType = conversion.Type;
Debug.Assert(typeof(System.MulticastDelegate).IsAssignableFrom(delegateType) && delegateType != typeof(System.MulticastDelegate));
MethodInfo method = delegateType.GetMethod("Invoke");
if (method.ReturnType == typeof(void))
{
throw Error.UserDefinedOperatorMustNotBeVoid(conversion, nameof(method));
}
ParameterInfo[] pms = method.GetParametersCached();
Debug.Assert(pms.Length == conversion.Parameters.Count);
if (pms.Length != 1)
{
throw Error.IncorrectNumberOfMethodCallArguments(conversion);
}
// The return type must match exactly.
// We could weaken this restriction and
// say that the return type must be assignable to from
// the return type of the lambda.
if (!TypeUtils.AreEquivalent(method.ReturnType, right.Type))
{
throw Error.OperandTypesDoNotMatchParameters(ExpressionType.Coalesce, conversion.ToString());
}
// The parameter of the conversion lambda must either be assignable
// from the erased or unerased type of the left hand side.
if (!ParameterIsAssignable(pms[0], TypeUtils.GetNonNullableType(left.Type)) &&
!ParameterIsAssignable(pms[0], left.Type))
{
throw Error.OperandTypesDoNotMatchParameters(ExpressionType.Coalesce, conversion.ToString());
}
return new CoalesceConversionBinaryExpression(left, right, conversion);
}
示例5: NotSupportedExpressionException
public NotSupportedExpressionException(LambdaExpression expression, string message, Exception innerException)
: base(message + Environment.NewLine + expression.ToString(), innerException)
{
Expression = expression;
}
示例6: GetFirstMember
private static MemberExpression GetFirstMember(LambdaExpression expression)
{
if (expression.Body is BinaryExpression)
return ((BinaryExpression)expression.Body).Left as MemberExpression;
if (expression.Body is MemberExpression)
return expression.Body as MemberExpression;
if (expression.Body is UnaryExpression && expression.Body.NodeType == ExpressionType.Convert)
return ((UnaryExpression)expression.Body).Operand as MemberExpression;
throw new UnableToGetTheFirstMember(expression.ToString());
}
示例7: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression m)
{
if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Where")
{
this.Visit(m.Arguments[0]);
queryTextBuilder.Append(" WHERE ");
LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
this.Visit(lambda.Body);
return m;
}
else if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Single")
{
this.Visit(m.Arguments[0]);
return m;
}
else if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Select")
{
this.Visit(m.Arguments[0]);
queryTextBuilder.Append(" SELECT ");
selectMethod = (LambdaExpression)StripQuotes(m.Arguments[1]);
queryTextBuilder.Append(selectMethod.ToString());
return m;
}
throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name));
}
示例8: ValidateConversion
private static Type ValidateConversion(CSharpExpressionType nodeType, Type inputType, LambdaExpression conversion)
{
var invoke = conversion.Type.GetMethod("Invoke");
var invokeParameters = invoke.GetParametersCached();
if (invokeParameters.Length != 1)
{
throw LinqError.IncorrectNumberOfMethodCallArguments(conversion);
}
if (!TypeUtils.AreEquivalent(invokeParameters[0].ParameterType, inputType))
{
throw LinqError.OperandTypesDoNotMatchParameters(nodeType, conversion.ToString());
}
return invoke.ReturnType;
}
示例9: GetLambda
private void GetLambda(LambdaExpression lambda)
{
if (lambda.Body.Type != typeof(void))
{
terms.Push(Expression.Constant(
new BoxedConstant(lambda.ToString()))
);
}
}