private bool InferConstructedType(IType formalType, IType actualType, TypeInference inference)
{
// look for a single occurance of the formal
// constructed type in the actual type's hierarchy
IType constructedActualType = GenericsServices.FindConstructedType(
actualType,
formalType.ConstructedInfo.GenericDefinition);
if (constructedActualType == null)
{
return(false);
}
// Exact inference requires the constructed occurance to be
// the actual type itself
if (inference == TypeInference.Exact && actualType != constructedActualType)
{
return(false);
}
for (int i = 0; i < formalType.ConstructedInfo.GenericArguments.Length; ++i)
{
bool inferenceSuccessful = Infer(
formalType.ConstructedInfo.GenericArguments[i],
constructedActualType.ConstructedInfo.GenericArguments[i],
TypeInference.Exact); // Generic arguments must match exactly, no variance allowed
if (!inferenceSuccessful)
{
return(false);
}
}
return(true);
}