Beispiel #1
0
        /// <summary>
        /// Constructs an entity from a generic definition and arguments, after ensuring the construction is valid.
        /// </summary>
        /// <param name="definition">The generic definition entity.</param>
        /// <param name="node">The node in which construction occurs.</param>
        /// <param name="argumentNodes">The nodes of the arguments supplied for generic construction.</param>
        /// <returns>The constructed entity.</returns>
        public IEntity ConstructEntity(IEntity definition, Node constructionNode, TypeReferenceCollection argumentNodes)
        {
            // Ambiguous generic constructions are handled separately
            if (definition.EntityType == EntityType.Ambiguous)
            {
                return ConstructAmbiguousEntity((Ambiguous)definition, constructionNode, argumentNodes);
            }

            // Check that the construction is valid
            if (!CheckGenericConstruction(definition, constructionNode, argumentNodes, Errors))
            {
                return TypeSystemServices.ErrorEntity;
            }

            // Construct a type or a method according to the definition
            IType[] arguments = Array.ConvertAll<TypeReference, IType>(
                argumentNodes.ToArray(),
                delegate(TypeReference tr) { return (IType)tr.Entity; });

            if (IsGenericType(definition))
            {
                return ((IType)definition).GenericInfo.ConstructType(arguments);
            }
            if (IsGenericMethod(definition))
            {
                return ((IMethod)definition).GenericInfo.ConstructMethod(arguments);
            }

            // Should never be reached - if definition is neither a generic type nor a generic method,
            // CheckGenericConstruction would've indicated this
            return TypeSystemServices.ErrorEntity;
        }
Beispiel #2
0
 private IType[] GetTypes(TypeReferenceCollection typeReferences)
 {
     return Array.ConvertAll<TypeReference, IType>(
         typeReferences.ToArray(),
         TypeSystemServices.GetType);
 }