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

GetMethodBasedUnaryOperator() private static method

private static GetMethodBasedUnaryOperator ( ExpressionType unaryType, Expression operand, MethodInfo method ) : UnaryExpression
unaryType ExpressionType
operand Expression
method System.Reflection.MethodInfo
return UnaryExpression
        private static UnaryExpression GetMethodBasedUnaryOperator(ExpressionType unaryType, Expression operand, 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))
            {
                ValidateParamswithOperandsOrThrow(pms[0].ParameterType, operand.Type, unaryType, method.Name);
                return new UnaryExpression(unaryType, operand, method.ReturnType, method);
            }
            // check for lifted call
            if (operand.Type.IsNullableType() &&
                ParameterIsAssignable(pms[0], operand.Type.GetNonNullableType()) &&
                method.ReturnType.GetTypeInfo().IsValueType && !method.ReturnType.IsNullableType())
            {
                return new UnaryExpression(unaryType, operand, method.ReturnType.GetNullableType(), method);
            }

            throw Error.OperandTypesDoNotMatchParameters(unaryType, method.Name);
        }
Expression