private static UnaryExpression GetUserDefinedUnaryOperator(ExpressionType unaryType, string name, Expression operand)
{
Type operandType = operand.Type;
Type[] types = new Type[] { operandType };
Type nnOperandType = operandType.GetNonNullableType();
MethodInfo method = nnOperandType.GetAnyStaticMethodValidated(name, types);
if (method != null)
{
return new UnaryExpression(unaryType, operand, method.ReturnType, method);
}
// try lifted call
if (operandType.IsNullableType())
{
types[0] = nnOperandType;
method = nnOperandType.GetAnyStaticMethodValidated(name, types);
if (method != null && method.ReturnType.GetTypeInfo().IsValueType && !method.ReturnType.IsNullableType())
{
return new UnaryExpression(unaryType, operand, method.ReturnType.GetNullableType(), method);
}
}
return null;
}