private bool ApplicableCandidate(Candidate candidate)
{
// Figure out whether method should be varargs-expanded
bool expand = ShouldExpandVarArgs(candidate);
// Determine number of fixed (non-varargs) parameters
int fixedParams =
(expand ? candidate.Parameters.Length - 1 : candidate.Parameters.Length);
// Validate number of parameters against number of arguments
if (_arguments.Count < fixedParams) return false;
if (_arguments.Count > fixedParams && !expand) return false;
// Score each argument against a fixed parameter
for (int i = 0; i < fixedParams; i++)
{
if (candidate.Score(i) < 0)
{
return false;
}
}
// If method should be expanded, match remaining arguments against
// last parameter
if (expand)
{
candidate.Expanded = true;
for (int i = fixedParams; i < _arguments.Count; i++)
{
if (candidate.ScoreVarArgs(i) < 0)
{
return false;
}
}
}
return true;
}