public TypeRefTypeSystemField(TypeRefTypeSystemType type, string name, TypeDesc fieldType, EmbeddedSignatureData[] embeddedSigData)
 {
     _type                  = type;
     _name                  = name;
     _fieldType             = fieldType;
     _embeddedSignatureData = embeddedSigData;
 }
Esempio n. 2
0
 private TypeRefTypeSystemType(string nameSpace, string name, TypeRefTypeSystemType containingType, TypeRefTypeSystemModule module)
 {
     _namespace      = nameSpace;
     _name           = name;
     _module         = module;
     _containingType = containingType;
 }
Esempio n. 3
0
        public override MetadataType GetNestedType(string name)
        {
            TypeRefTypeSystemType type = null;

            if (_nestedType != null)
            {
                _nestedType.TryGetValue(name, out type);
            }
            return(type);
        }
Esempio n. 4
0
        public TypeRefTypeSystemType GetOrAddNestedType(string name)
        {
            if (_nestedType == null)
            {
                _nestedType = new Dictionary <string, TypeRefTypeSystemType>();
            }

            if (!_nestedType.TryGetValue(name, out TypeRefTypeSystemType type))
            {
                type = new TypeRefTypeSystemType(null, name, this, _module);
                _nestedType.Add(name, type);
            }

            return(type);
        }
Esempio n. 5
0
 public TypeRefTypeSystemMethod(TypeRefTypeSystemType type, string name, MethodSignature signature)
 {
     _type      = type;
     _name      = name;
     _signature = signature;
     if (signature.GenericParameterCount == 0)
     {
         _instantiation = Instantiation.Empty;
     }
     else
     {
         TypeDesc[] instantiationArgs = new TypeDesc[signature.GenericParameterCount];
         for (int i = 0; i < signature.GenericParameterCount; i++)
         {
             instantiationArgs[i] = new TypeRefTypeSystemGenericParameter(this, i);
         }
         _instantiation = new Instantiation(instantiationArgs);
     }
 }
Esempio n. 6
0
        public TypeRefTypeSystemType GetOrAddType(string nameSpace, string name)
        {
            TypeRefTypeSystemType type = GetTypeInternal(nameSpace, name);

            if (type == null)
            {
                type = new TypeRefTypeSystemType(nameSpace, name, this);

                Dictionary <string, TypeRefTypeSystemType> nameToTypeDictionary = _nonNamespacedTypes;
                if (!String.IsNullOrEmpty(nameSpace))
                {
                    if (!_namespacedTypes.TryGetValue(nameSpace, out nameToTypeDictionary))
                    {
                        nameToTypeDictionary = new Dictionary <string, TypeRefTypeSystemType>();
                        _namespacedTypes.Add(nameSpace, nameToTypeDictionary);
                    }
                }

                nameToTypeDictionary.Add(name, type);
                _types.Add(type);
            }

            return(type);
        }
Esempio n. 7
0
        public TypeRefTypeSystemContext(IEnumerable <PEReader> refReaders)
        {
            _refReaders = refReaders.ToArray();

            TypeRefTypeSystemModule coreLibModule = new TypeRefTypeSystemModule(this, new System.Reflection.AssemblyName("System.Private.CoreLib"));

            foreach (string name in MetadataTypeSystemContext.WellKnownTypeNames)
            {
                coreLibModule.GetOrAddType("System", name);
            }

            _typeRefModules.Add(coreLibModule.Assembly.GetName().Name, coreLibModule);

            SetSystemModule(coreLibModule);

            // Read every signature and hydrate the types that are possible
            List <PEInfo> peInfos = new List <PEInfo>();

            foreach (PEReader pe in refReaders)
            {
                peInfos.Add(new PEInfo(pe));
            }

            // Walk all signature blobs and find out which types are valuetypes/generic
            foreach (PEInfo peInfo in peInfos)
            {
                TypeRefSignatureParserProvider parserHelper = new TypeRefSignatureParserProvider(this, peInfo.handleLookup);
                // Resolve every type ref, so that the full set of type refs is known
                foreach (var typeRefHandle in peInfo.reader.TypeReferences)
                {
                    ResolveTypeRef(peInfo, typeRefHandle);
                }

                int typeSpecRowCount = peInfo.reader.GetTableRowCount(TableIndex.TypeSpec);
                for (int row = 1; row <= typeSpecRowCount; row++)
                {
                    var handle   = MetadataTokens.TypeSpecificationHandle(row);
                    var typeSpec = peInfo.reader.GetTypeSpecification(handle);
                    typeSpec.DecodeSignature(parserHelper, null);
                }

                int standAloneSigRowCount = peInfo.reader.GetTableRowCount(TableIndex.StandAloneSig);
                for (int row = 1; row <= standAloneSigRowCount; row++)
                {
                    var handle        = MetadataTokens.StandaloneSignatureHandle(row);
                    var standaloneSig = peInfo.reader.GetStandaloneSignature(handle);
                    if (standaloneSig.GetKind() == StandaloneSignatureKind.LocalVariables)
                    {
                        standaloneSig.DecodeLocalSignature(parserHelper, null);
                    }
                    else
                    {
                        standaloneSig.DecodeMethodSignature(parserHelper, null);
                    }
                }

                int memberRefRowCount = peInfo.reader.GetTableRowCount(TableIndex.MemberRef);
                for (int row = 1; row <= memberRefRowCount; row++)
                {
                    var handle    = MetadataTokens.MemberReferenceHandle(row);
                    var memberRef = peInfo.reader.GetMemberReference(handle);
                    if (memberRef.GetKind() == MemberReferenceKind.Method)
                    {
                        memberRef.DecodeMethodSignature(parserHelper, null);
                    }
                    else
                    {
                        memberRef.DecodeFieldSignature(parserHelper, null);
                    }
                }

                int methodSpecRowCount = peInfo.reader.GetTableRowCount(TableIndex.MethodSpec);
                for (int row = 1; row <= methodSpecRowCount; row++)
                {
                    var handle     = MetadataTokens.MethodSpecificationHandle(row);
                    var methodSpec = peInfo.reader.GetMethodSpecification(handle);
                    methodSpec.DecodeSignature(parserHelper, null);
                }
            }

            // Walk all memberrefs, and attach fields/methods to types
            foreach (PEInfo peInfo in peInfos)
            {
                TypeRefSignatureParserProvider parserHelper = new TypeRefSignatureParserProvider(this, peInfo.handleLookup);

                Func <EntityHandle, NotFoundBehavior, TypeDesc> resolverFunc = ResolveTypeRefForPeInfo;
                int memberRefRowCount = peInfo.reader.GetTableRowCount(TableIndex.MemberRef);
                for (int row = 1; row <= memberRefRowCount; row++)
                {
                    var handle    = MetadataTokens.MemberReferenceHandle(row);
                    var memberRef = peInfo.reader.GetMemberReference(handle);

                    TypeRefTypeSystemType ownerType = null;
                    if (memberRef.Parent.Kind == HandleKind.TypeReference)
                    {
                        ownerType = ResolveTypeRef(peInfo, (TypeReferenceHandle)memberRef.Parent);
                    }
                    else if (memberRef.Parent.Kind == HandleKind.TypeSpecification)
                    {
                        TypeDesc t = parserHelper.GetTypeFromSpecification(peInfo.reader, null, (TypeSpecificationHandle)memberRef.Parent, 0);
                        ownerType = t.GetTypeDefinition() as TypeRefTypeSystemType;
                    }
                    if (ownerType == null)
                    {
                        continue;
                    }

                    EcmaSignatureParser ecmaSigParse = new EcmaSignatureParser(this, ResolveTypeRefForPeInfo, peInfo.reader.GetBlobReader(memberRef.Signature), NotFoundBehavior.ReturnNull);
                    string name = peInfo.reader.GetString(memberRef.Name);

                    if (memberRef.GetKind() == MemberReferenceKind.Method)
                    {
                        var methodSig = ecmaSigParse.ParseMethodSignature();
                        ownerType.GetOrAddMethod(name, methodSig);
                    }
                    else
                    {
                        var fieldType = ecmaSigParse.ParseFieldSignature();
                        ownerType.GetOrAddField(name, fieldType);
                    }
                }

                TypeDesc ResolveTypeRefForPeInfo(EntityHandle handle, NotFoundBehavior notFoundBehavior)
                {
                    Debug.Assert(notFoundBehavior == NotFoundBehavior.ReturnNull);
                    TypeRefTypeSystemType type = null;

                    if (handle.Kind == HandleKind.TypeReference)
                    {
                        peInfo.handleLookup.TryGetValue((TypeReferenceHandle)handle, out type);
                    }
                    return(type);
                }
            }
        }
 public TypeRefTypeSystemField(TypeRefTypeSystemType type, string name, TypeDesc fieldType)
 {
     _type      = type;
     _name      = name;
     _fieldType = fieldType;
 }
Esempio n. 9
0
 internal TypeRefTypeSystemGenericParameter(TypeRefTypeSystemType owningType, int index)
 {
     _owningType = owningType;
     _index      = index;
 }