Beispiel #1
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");
            }
        }
Beispiel #2
0
        private void Initialize(
            MethodDefinitionHandle methodDefinitionHandle,
            MrType declaringType,
            MethodDefinition methodDefinition)
        {
            SetDeclaringType(declaringType);
            MethodDefinitionHandle = methodDefinitionHandle;

            MethodDefinition = methodDefinition;

            // Decode the method signature

            var genericMethodParameters
                = MethodDefinition
                  .GetGenericParameters()
                  .Select(h => MrType.CreateFromGenericParameterHandle(h, DeclaringType.Assembly))
                  .ToImmutableArray();

            var context = new MRGenericContext(DeclaringType.GetGenericTypeParameters(), genericMethodParameters);

            MethodSignature = MethodDefinition.DecodeSignature <MrType, MRGenericContext>(
                DeclaringType.Assembly.TypeProvider,
                context);
        }