MethodBase GetBetterMethod (MethodBase m1, MethodBase m2, Type [] types)
{
#if NET_2_0
if (m1.IsGenericMethodDefinition &&
!m2.IsGenericMethodDefinition)
return m2;
if (m2.IsGenericMethodDefinition &&
!m1.IsGenericMethodDefinition)
return m1;
#endif
ParameterInfo [] pl1 = m1.GetParameters ();
ParameterInfo [] pl2 = m2.GetParameters ();
int prev = 0;
for (int i = 0; i < pl1.Length; i++) {
int cmp = CompareCloserType (pl1 [i].ParameterType, pl2 [i].ParameterType);
if (cmp != 0 && prev != 0 && prev != cmp)
throw new AmbiguousMatchException ();
if (cmp != 0)
prev = cmp;
}
if (prev != 0)
return prev > 0 ? m2 : m1;
Type dt1 = m1.DeclaringType;
Type dt2 = m2.DeclaringType;
if (dt1 != dt2) {
if (dt1.IsSubclassOf(dt2))
return m1;
if (dt2.IsSubclassOf(dt1))
return m2;
}
bool va1 = (m1.CallingConvention & CallingConventions.VarArgs) != 0;
bool va2 = (m2.CallingConvention & CallingConventions.VarArgs) != 0;
if (va1 && !va2)
return m2;
if (va2 && !va1)
return m1;
throw new AmbiguousMatchException ();
}