private IType GetParameterTypeTemplate(Candidate candidate, int position)
{
// Get the method this candidate represents, or its generic template
IMethod method = candidate.Method;
if (candidate.Method.DeclaringType.ConstructedInfo != null)
{
method = candidate.Method.DeclaringType.ConstructedInfo.GetMethodTemplate(method);
}
if (candidate.Method.ConstructedInfo != null)
{
method = candidate.Method.ConstructedInfo.GenericDefinition;
}
// If the parameter is the varargs parameter, use its element type
IParameter[] parameters = method.GetParameters();
if (candidate.Expanded && position >= parameters.Length)
{
return parameters[parameters.Length - 1].Type.GetElementType();
}
// Otherwise use the parameter's original type
return parameters[position].Type;
}