System.Linq.Expressions.Expression.GetMethodBasedCoercionOperator C# (CSharp) Method

GetMethodBasedCoercionOperator() private static method

private static GetMethodBasedCoercionOperator ( ExpressionType unaryType, Expression operand, Type convertToType, MethodInfo method ) : UnaryExpression
unaryType ExpressionType
operand Expression
convertToType Type
method System.Reflection.MethodInfo
return UnaryExpression
        private static UnaryExpression GetMethodBasedCoercionOperator(ExpressionType unaryType, Expression operand, Type convertToType, MethodInfo method)
        {
            Debug.Assert(method != null);
            ValidateOperator(method);
            ParameterInfo[] pms = method.GetParametersCached();
            if (pms.Length != 1)
            {
                throw Error.IncorrectNumberOfMethodCallArguments(method, nameof(method));
            }
            if (ParameterIsAssignable(pms[0], operand.Type) && TypeUtils.AreEquivalent(method.ReturnType, convertToType))
            {
                return new UnaryExpression(unaryType, operand, method.ReturnType, method);
            }
            // check for lifted call
            if ((operand.Type.IsNullableType() || convertToType.IsNullableType()) &&
                ParameterIsAssignable(pms[0], operand.Type.GetNonNullableType()) &&
                (TypeUtils.AreEquivalent(method.ReturnType, convertToType.GetNonNullableType()) ||
                TypeUtils.AreEquivalent(method.ReturnType, convertToType)))
            {
                return new UnaryExpression(unaryType, operand, convertToType, method);
            }
            throw Error.OperandTypesDoNotMatchParameters(unaryType, method.Name);
        }
Expression