private int BetterCandidate(Candidate c1, Candidate c2)
{
if (c1 == c2) return 0;
int result = Math.Sign(TotalScore(c1) - TotalScore(c2));
// int result = 0;
/*
if (false)
{
for (int i = 0; i < _arguments.Count; i++)
{
// Compare methods based on their score for the current argument
int better = Math.Sign(c1.ArgumentScores[i] - c2.ArgumentScores[i]);
if (better == 0) continue;
// If neither method has been selecteed yet, select one
// based on this argument
if (result == 0)
{
result = better;
}
// If this argument comparison is in conflict with previous selection,
// neither method is better
else if (result != better)
{
return 0;
}
}
}
*/
if (result != 0)
{
return result;
}
// Prefer methods declared on deeper types
result =
c1.Method.DeclaringType.GetTypeDepth() -
c2.Method.DeclaringType.GetTypeDepth();
if (result != 0) return result;
// Prefer methods with less generic parameters
result =
GenericsServices.GetMethodGenerity(c2.Method) -
GenericsServices.GetMethodGenerity(c1.Method);
if (result != 0) return result;
// --- Tie breaking mode! ---
// Non-expanded methods are better than expanded ones
if (!c1.Expanded && c2.Expanded)
{
return 1;
}
else if (c1.Expanded && !c2.Expanded)
{
return -1;
}
// An expanded method with more fixed parameters is better
result = c1.Parameters.Length - c2.Parameters.Length;
if (result != 0) return result;
// As a last means of breaking this desperate tie, we select the
// "more specific" candidate, if one exists
return MoreSpecific(c1, c2);
}