Esempio n. 1
0
        void EnsureTypesAreLoaded()
        {
            if (_nameToMrType != null || IsFakeAssembly)
            {
                return;
            }

            var typeDefinitions = Reader.TypeDefinitions;

            _nameToMrType = new Dictionary <string, MrType>(typeDefinitions.Count);
            foreach (var typeDefinitionHandle in Reader.TypeDefinitions)
            {
                var mrType = MrType.CreateFromTypeDefinition(typeDefinitionHandle, this);
                _nameToMrType[mrType.GetFullName()] = mrType;
            }
        }
        public ImmutableArray <MrType> GetNestedTypes()
        {
            List <MrType> mrTypeList = null;
            var           nestedTypeDefinitionHandles = this.TypeDefinition.GetNestedTypes();

            foreach (var nestedTypeDefinition in nestedTypeDefinitionHandles)
            {
                if (mrTypeList == null)
                {
                    mrTypeList = new List <MrType>();
                }
                mrTypeList.Add(MrType.CreateFromTypeDefinition(nestedTypeDefinition, this.Assembly));
            }

            return(mrTypeList == null ? ImmutableArray <MrType> .Empty : mrTypeList.ToImmutableArray());
        }
Esempio n. 3
0
        public MrType GetTypeFromEntityHandle(EntityHandle baseTypeEntityHandle, TypeDefinition typeDefinition)
        {
            var provider = new DisassemblingTypeProvider(this);

            switch (baseTypeEntityHandle.Kind)
            {
            case HandleKind.TypeDefinition:
            {
                var baseTypeDefinitionHandle = (TypeDefinitionHandle)baseTypeEntityHandle;
                //var baseTypeHandleWrapper = GetTypeFromEntityHandle(typeDefinition, baseTypeDefinitionHandle);
                var baseTypeHandleWrapper = MrType.CreateFromTypeDefinition(baseTypeDefinitionHandle, this);
                return(baseTypeHandleWrapper);
            }

            //case HandleKind.TypeDefinition:
            //    type = GetTypeOfTypeDef((TypeDefinitionHandle)token, out isNoPiaLocalType, isContainingType: false);
            //    break;

            case HandleKind.TypeSpecification:
            {
                var typeSpecification = Reader.GetTypeSpecification((TypeSpecificationHandle)baseTypeEntityHandle);


                var genericTypeParameters = typeDefinition
                                            .GetGenericParameters()
                                            .Select(h => MrType.CreateFromGenericParameterHandle(h, this))
                                            .ToImmutableArray();

                var context = new MRGenericContext(genericTypeParameters, ImmutableArray <MrType> .Empty);

                var mrType = typeSpecification.DecodeSignature(provider, context);
                return(mrType);
            }


            case HandleKind.TypeReference:
            {
                var referencedTypeDefinitionHandleWrapper = _loadContext.GetTypeFromReference(Reader, (TypeReferenceHandle)baseTypeEntityHandle);
                return(referencedTypeDefinitionHandleWrapper);
            }

            default:
                throw new Exception("Unknown entity type");
            }
        }
 static public MrType AsMrType(this TypeDefinitionHandle handle, MrAssembly assembly)
 {
     return(MrType.CreateFromTypeDefinition(handle, assembly));
 }