+ if (expression == null)
+ throw new ArgumentNullException ("expression");
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ var et = expression.Type;
+
+ if (method != null)
+ CheckUnaryMethod (method, et);
+ else if (!IsPrimitiveConversion (et, type) && !IsReferenceConversion (et, type))
+ method = GetUserConversionMethod (et, type);
+
+ return new UnaryExpression (ExpressionType.Convert,
+ expression, type, method,
+ IsConvertNodeLifted (method, expression, type));
+ }
+
+ static bool IsConvertNodeLifted (MethodInfo method, Expression operand, Type target)
+ {
+ if (method == null)
+ return operand.Type.IsNullable () || target.IsNullable ();
+
+ if (operand.Type.IsNullable () && !ParameterMatch (method, operand.Type))
+ return true;
+
+ if (target.IsNullable () && !ReturnTypeMatch (method, target))
+ return true;
+
+ return false;
+ }
+
+ static bool ParameterMatch (MethodInfo method, Type type)
+ {
+ return method.GetParameters () [0].ParameterType == type;
+ }
+
+ static bool ReturnTypeMatch (MethodInfo method, Type type)
+ {
+ return method.ReturnType == type;