Ejemplo n.º 1
0
        public ConstructedType(Context cx, Type unboundType, IEnumerable <Type> typeArguments) : base(cx)
        {
            idWriter = new NamedTypeIdWriter(this);
            var suppliedArgs = typeArguments.Count();

            if (suppliedArgs != unboundType.TotalTypeParametersCount)
            {
                throw new InternalError("Unexpected number of type arguments in ConstructedType");
            }

            unboundGenericType = unboundType;
            var thisParams = unboundType.ThisTypeParameterCount;

            if (typeArguments.Count() == thisParams)
            {
                containingType    = unboundType.ContainingType;
                thisTypeArguments = typeArguments.ToArray();
            }
            else if (thisParams == 0)
            {
                // all type arguments belong to containing type
                containingType = unboundType.ContainingType !.Construct(typeArguments);
            }
            else
            {
                // some type arguments belong to containing type
                var parentParams = suppliedArgs - thisParams;
                containingType    = unboundType.ContainingType !.Construct(typeArguments.Take(parentParams));
                thisTypeArguments = typeArguments.Skip(parentParams).ToArray();
            }
        }
Ejemplo n.º 2
0
 public TypeReferenceType(Context cx, TypeReferenceHandle handle) : base(cx)
 {
     this.idWriter   = new NamedTypeIdWriter(this);
     this.handle     = handle;
     this.tr         = cx.MdReader.GetTypeReference(handle);
     this.typeParams = new Lazy <TypeTypeParameter[]>(GenericsHelper.MakeTypeParameters(this, ThisTypeParameterCount));
 }
Ejemplo n.º 3
0
        public TypeDefinitionType(Context cx, TypeDefinitionHandle handle) : base(cx)
        {
            idWriter    = new NamedTypeIdWriter(this);
            td          = cx.MdReader.GetTypeDefinition(handle);
            this.handle = handle;

            declType =
                td.GetDeclaringType().IsNil ? null :
                (Type)cx.Create(td.GetDeclaringType());

            // Lazy because should happen during population.
            typeParams = new Lazy <IEnumerable <TypeTypeParameter> >(MakeTypeParameters);
        }
Ejemplo n.º 4
0
        public NoMetadataHandleType(Context cx, string originalName) : base(cx)
        {
            this.originalName = originalName;
            this.idWriter     = new NamedTypeIdWriter(this);

            var nameParser = new FullyQualifiedNameParser(originalName);

            name                 = nameParser.ShortName;
            assemblyName         = nameParser.AssemblyName;
            isContainerNamespace = nameParser.IsContainerNamespace;
            containerName        = nameParser.ContainerName;

            unboundGenericType = nameParser.UnboundGenericTypeName is null
                ? this
                : new NoMetadataHandleType(Context, nameParser.UnboundGenericTypeName);

            if (nameParser.TypeArguments is not null)
            {
                thisTypeArguments = nameParser.TypeArguments.Select(t => new NoMetadataHandleType(Context, t)).ToArray();
            }
            else
            {
                typeParams = new Lazy <TypeTypeParameter[]>(GenericsHelper.MakeTypeParameters(this, ThisTypeParameterCount));
            }

            containingType = isContainerNamespace
                ? null
                : new NoMetadataHandleType(Context, containerName);

            containingNamespace = isContainerNamespace
                ? containerName == Context.GlobalNamespace.Name
                    ? Context.GlobalNamespace
                    : containerName == Context.SystemNamespace.Name
                        ? Context.SystemNamespace
                        : new Namespace(Context, containerName)
                : null;

            Populate();
        }