private static int PreferSignature(object[] args, Type[] sig1, bool vararg1, Type[] sig2, bool vararg2)
{
int totalPreference = 0;
for (int j = 0; j < args.Length; j++)
{
Type type1 = vararg1 && j >= sig1.Length ? sig1[sig1.Length - 1] : sig1[j];
Type type2 = vararg2 && j >= sig2.Length ? sig2[sig2.Length - 1] : sig2[j];
if (type1 == type2)
{
continue;
}
object arg = args[j];
// Determine which of type1, type2 is easier to convert from arg.
int rank1 = NativeJavaObject.GetConversionWeight(arg, type1);
int rank2 = NativeJavaObject.GetConversionWeight(arg, type2);
int preference;
if (rank1 < rank2)
{
preference = PREFERENCE_FIRST_ARG;
}
else
{
if (rank1 > rank2)
{
preference = PREFERENCE_SECOND_ARG;
}
else
{
// Equal ranks
if (rank1 == NativeJavaObject.CONVERSION_NONTRIVIAL)
{
if (type1.IsAssignableFrom(type2))
{
preference = PREFERENCE_SECOND_ARG;
}
else
{
if (type2.IsAssignableFrom(type1))
{
preference = PREFERENCE_FIRST_ARG;
}
else
{
preference = PREFERENCE_AMBIGUOUS;
}
}
}
else
{
preference = PREFERENCE_AMBIGUOUS;
}
}
}
totalPreference |= preference;
if (totalPreference == PREFERENCE_AMBIGUOUS)
{
break;
}
}
return totalPreference;
}