static private ConversionInvalidArgument ( object p0, object p1 ) : |
||
p0 | object | |
p1 | object | |
리턴 |
private static void ValidateConversion(Type variableType, Type elementType, ref LambdaExpression conversion) { if (conversion != null) { if (conversion.Parameters.Count != 1) { throw Error.ConversionNeedsOneParameter(); } var convertParameterType = conversion.Parameters[0].Type; var convertResultType = conversion.Body.Type; if (!AreReferenceAssignable(convertParameterType, elementType)) { throw Error.ConversionInvalidArgument(elementType, convertParameterType); } if (!AreReferenceAssignable(variableType, convertResultType)) { throw Error.ConversionInvalidResult(convertResultType, variableType); } } else if (!AreReferenceAssignable(variableType, elementType)) { var element = Expression.Parameter(elementType, "__element"); // NB: The LINQ factory will perform the necessary checks. // NB: If checked conversion is needed, one should explicitly specify a conversion lambda. var convert = Expression.Convert(element, variableType); conversion = Expression.Lambda(convert, element); } }