Boo.Lang.Compiler.TypeSystem.GenericsServices.ConstructAmbiguousEntity C# (CSharp) Method

ConstructAmbiguousEntity() private method

Constructs generic entities out of an ambiguous definition.
private ConstructAmbiguousEntity ( Node constructionNode, Ambiguous ambiguousDefinition, IType typeArguments ) : IEntity
constructionNode Node
ambiguousDefinition Ambiguous
typeArguments IType
return IEntity
        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);
        }