public static MethodInfo GetUserDefinedCoercionMethod(Type convertFrom, Type convertToType)
{
Type nnExprType = GetNonNullableType(convertFrom);
Type nnConvType = GetNonNullableType(convertToType);
// try exact match on types
MethodInfo[] eMethods = nnExprType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
MethodInfo method = FindConversionOperator(eMethods, convertFrom, convertToType);
if (method != null)
{
return method;
}
MethodInfo[] cMethods = nnConvType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
method = FindConversionOperator(cMethods, convertFrom, convertToType);
if (method != null)
{
return method;
}
if (AreEquivalent(nnExprType, convertFrom) && AreEquivalent(nnConvType, convertToType))
{
return null;
}
// try lifted conversion
return FindConversionOperator(eMethods, nnExprType, nnConvType)
?? FindConversionOperator(cMethods, nnExprType, nnConvType)
?? FindConversionOperator(eMethods, nnExprType, convertToType)
?? FindConversionOperator(cMethods, nnExprType, convertToType);
}