private IEntity ConstructAmbiguousEntity(Node constructionNode, Ambiguous ambiguousDefinition, IType[] typeArguments)
{
GenericConstructionChecker checker = new GenericConstructionChecker(
TypeSystemServices,
constructionNode,
typeArguments,
new CompilerErrorCollection());
List<IEntity> matches = new List<IEntity>(ambiguousDefinition.Entities);
// Filter matches by genericness, generity and constraints
Predicate<IEntity>[] filters = new Predicate<IEntity>[] {
checker.NotGenericDefinition,
checker.IncorrectGenerity,
checker.ViolatesParameterConstraints };
foreach (Predicate<IEntity> filter in filters)
{
checker.Errors.Clear();
matches.RemoveAll(filter);
// If no matches pass the filter, record the first error only
// (providing all the distinct errors that occured would be superfluous)
if (matches.Count == 0)
{
Errors.Add(checker.Errors[0]);
return TypeSystemServices.ErrorEntity;
}
// If only one match passes the filter, continue construction normally
if (matches.Count == 1)
{
return ConstructEntity(constructionNode, matches[0], typeArguments);
}
}
// Several matches have passed the filter -
// construct all of them and return another Ambiguous entity
IEntity[] constructed = Array.ConvertAll<IEntity, IEntity>(
matches.ToArray(),
delegate(IEntity def) { return ConstructEntity(constructionNode, def, typeArguments); });
return new Ambiguous(constructed);
}