本文整理汇总了C#中LambdaExpression.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LambdaExpression.ToString方法的具体用法?C# LambdaExpression.ToString怎么用?C# LambdaExpression.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LambdaExpression
的用法示例。
在下文中一共展示了LambdaExpression.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
}
示例2: 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, "left");
RequiresCanRead(right, "right");
if (conversion == null) {
Type resultType = ValidateCoalesceArgTypes(left.Type, right.Type);
return new SimpleBinaryExpression(ExpressionType.Coalesce, left, right, resultType);
}
if (left.Type.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);
}
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.
// CONSIDER: We could weaken this restriction and
// CONSIDER: say that the return type must be assignable to from
// CONSIDER: 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);
}