/// <summary> /// Validates and constructs generic entities out of an ambiguous generic definition entity. /// </summary> private IEntity ConstructAmbiguousEntity(Node constructionNode, Ambiguous ambiguousDefinition, IType[] typeArguments) { var checker = new GenericConstructionChecker(typeArguments, constructionNode); var matches = new List <IEntity>(ambiguousDefinition.Entities); bool reportErrors = false; foreach (Predicate <IEntity> check in checker.Checks) { matches = matches.Collect(check); if (matches.Count == 0) { Errors.Add(checker.Errors[0]); // only report first error, assuming the rest are superfluous return(TypeSystemServices.ErrorEntity); } if (reportErrors) { checker.ReportErrors(Errors); } checker.DiscardErrors(); // We only want full error reporting once we get down to a single candidate if (matches.Count == 1) { reportErrors = true; } } IEntity[] constructedMatches = Array.ConvertAll <IEntity, IEntity>(matches.ToArray(), def => MakeGenericEntity(def, typeArguments)); return(Entities.EntityFromList(constructedMatches)); }
/// <summary> /// Validates and constructs generic entities out of an ambiguous generic definition entity. /// </summary> private IEntity ConstructAmbiguousEntity(Node constructionNode, Ambiguous ambiguousDefinition, IType[] typeArguments) { var checker = new GenericConstructionChecker(typeArguments, constructionNode); var matches = new List<IEntity>(ambiguousDefinition.Entities); bool reportErrors = false; foreach (Predicate<IEntity> check in checker.Checks) { matches = matches.Collect(check); if (matches.Count == 0) { Errors.Add(checker.Errors[0]); // only report first error, assuming the rest are superfluous return TypeSystemServices.ErrorEntity; } if (reportErrors) checker.ReportErrors(Errors); checker.DiscardErrors(); // We only want full error reporting once we get down to a single candidate if (matches.Count == 1) reportErrors = true; } IEntity[] constructedMatches = Array.ConvertAll<IEntity, IEntity>(matches.ToArray(), def => MakeGenericEntity(def, typeArguments)); return Entities.EntityFromList(constructedMatches); }
/// <summary> /// Checks whether a given set of arguments can be used to construct a generic type or method from a specified definition. /// </summary> public bool CheckGenericConstruction(Node node, IEntity definition, IType[] typeArguments, bool reportErrors) { var checker = new GenericConstructionChecker(typeArguments, node); foreach (Predicate <IEntity> check in checker.Checks) { if (check(definition)) { continue; } if (reportErrors) { checker.ReportErrors(Errors); } return(false); } return(true); }
/// <summary> /// Checks whether a given set of arguments can be used to construct a generic type or method from a specified definition. /// </summary> public bool CheckGenericConstruction(Node node, IEntity definition, IType[] typeArguments, bool reportErrors) { var checker = new GenericConstructionChecker(typeArguments, node); foreach (Predicate<IEntity> check in checker.Checks) { if (check(definition)) continue; if (reportErrors) checker.ReportErrors(Errors); return false; } return true; }