A type constructed by supplying type parameters to a generic type, involving internal types.
Constructed types constructed from an external generic type with external type arguments are themselves external, and are represented as ExternalType instances. All other cases are represented by this type.
Наследование: IType, IConstructedTypeInfo
Пример #1
0
        public MethodInvocationExpression CreateGenericConstructorInvocation(IType classType,
                                                                             IEnumerable <TypeReference> genericArgs)
        {
            var          gpp = classType as IGenericParametersProvider;
            IConstructor constructor;

            if (gpp == null || !genericArgs.Any())
            {
                constructor = classType.GetConstructors().First();
                return(CreateConstructorInvocation(constructor));
            }

            classType = new GenericConstructedType(
                classType,
                genericArgs.Select(a => a.Entity).Cast <IType>().ToArray());
            constructor = classType.GetConstructors().First();

            var result = new MethodInvocationExpression {
                Target = CreateReference(constructor.DeclaringType)
            };

            result.Target.Entity  = constructor;
            result.ExpressionType = constructor.DeclaringType;

            return(result);
        }
Пример #2
0
        IType GetEnumeratorItemTypeFromAttribute(IType iteratorType)
        {
            // If iterator type is external get its attributes via reflection
            if (iteratorType is ExternalType)
            {
                return(GetExternalEnumeratorItemType(iteratorType));
            }

            // If iterator type is a generic constructed type, map its attribute from its definition
            GenericConstructedType constructedType = iteratorType as GenericConstructedType;

            if (constructedType != null)
            {
                return(constructedType.GenericMapping.Map(
                           GetEnumeratorItemTypeFromAttribute(constructedType.GenericDefinition)));
            }

            // If iterator type is internal get its attributes from its type definition
            AbstractInternalType internalType = (AbstractInternalType)iteratorType;
            IType enumeratorItemTypeAttribute = Map(typeof(EnumeratorItemTypeAttribute));

            foreach (Attribute attribute in internalType.TypeDefinition.Attributes)
            {
                IConstructor constructor = GetEntity(attribute) as IConstructor;
                if (null != constructor)
                {
                    if (constructor.DeclaringType == enumeratorItemTypeAttribute)
                    {
                        return(GetType(attribute.Arguments[0]));
                    }
                }
            }
            return(null);
        }