Example #1
0
        public void AddModuleTokenForType(TypeDesc type, ModuleToken token)
        {
            bool specialTypeFound = false;

            // Collect underlying type tokens for type specifications
            if (token.TokenType == CorTokenType.mdtTypeSpec)
            {
                TypeSpecification typeSpec = token.MetadataReader.GetTypeSpecification((TypeSpecificationHandle)token.Handle);
                typeSpec.DecodeSignature(new TokenResolverProvider(this, token.Module), this);
                specialTypeFound = true;
            }

            if (_compilationModuleGroup.VersionsWithType(type))
            {
                // We don't need to store handles within the current compilation group
                // as we can read them directly from the ECMA objects.
                return;
            }

            if (type is EcmaType ecmaType)
            {
                // Don't store typespec tokens where a generic parameter resolves to the type in question
                if (token.TokenType == CorTokenType.mdtTypeDef || token.TokenType == CorTokenType.mdtTypeRef)
                {
                    SetModuleTokenForTypeSystemEntity(_typeToRefTokens, ecmaType, token);
                }
            }
            else if (!specialTypeFound)
            {
                throw new NotImplementedException(type.ToString());
            }
        }
Example #2
0
            public DummyTypeInfo GetTypeFromSpecification(MetadataReader reader, ModuleTokenResolver genericContext, TypeSpecificationHandle handle, byte rawTypeKind)
            {
                TypeSpecification typeSpec = reader.GetTypeSpecification(handle);

                typeSpec.DecodeSignature(this, genericContext);
                return(DummyTypeInfo.Instance);
            }
Example #3
0
        /// <summary>
        /// Emit an arbitrary type specification.
        /// </summary>
        /// <param name="typeSpecHandle">Type specification handle</param>
        /// <param name="namespaceQualified">When set to true, include namespace information</param>
        private string EmitTypeSpecificationName(TypeSpecificationHandle typeSpecHandle, bool namespaceQualified)
        {
            TypeSpecification           typeSpec       = _metadataReader.GetTypeSpecification(typeSpecHandle);
            DisassemblingGenericContext genericContext = new DisassemblingGenericContext(Array.Empty <string>(), Array.Empty <string>());

            return(typeSpec.DecodeSignature <string, DisassemblingGenericContext>(this, genericContext));
        }
Example #4
0
        //
        // Main routine to parse a metadata type specification signature.
        //
        private static RuntimeTypeInfo TryResolveTypeSignature(this TypeSpecificationHandle typeSpecHandle, MetadataReader reader, TypeContext typeContext, ref Exception exception)
        {
            TypeSpecification      typeSpec        = reader.GetTypeSpecification(typeSpecHandle);
            ReflectionTypeProvider refTypeProvider = new ReflectionTypeProvider(throwOnError: false);
            RuntimeTypeInfo        result          = typeSpec.DecodeSignature <RuntimeTypeInfo, TypeContext>(refTypeProvider, typeContext);

            exception = refTypeProvider.ExceptionResult;
            return(result);
        }
Example #5
0
 private void ReadCustomAttributeTypeNameWithoutResolving(EntityHandle customAttributeConstructorHandle, out string customAttributeTypeNamespace, out string customAttributeTypeName)
 {
     /**
      * It is possible that the assembly that defines the attribute is not provided as a reference assembly.
      *
      * Most the time, as long as the custom attribute is not accessed or the reference assembly is available at runtime, the code will work just fine.
      *
      * If we used _module.GetMethod(customAttributeConstructorHandle), we should have caused an exception and failing the compilation.
      *
      * Therefore, we have this alternate path to obtain the type namespace and name.
      */
     if (customAttributeConstructorHandle.Kind == HandleKind.MethodDefinition)
     {
         MethodDefinitionHandle customAttributeConstructorDefinitionHandle     = (MethodDefinitionHandle)customAttributeConstructorHandle;
         MethodDefinition       customAttributeConstructorDefinition           = _module.MetadataReader.GetMethodDefinition(customAttributeConstructorDefinitionHandle);
         TypeDefinitionHandle   customAttributeConstructorTypeDefinitionHandle = customAttributeConstructorDefinition.GetDeclaringType();
         GetTypeNameFromTypeDefinitionHandle(customAttributeConstructorTypeDefinitionHandle, out customAttributeTypeNamespace, out customAttributeTypeName);
     }
     else if (customAttributeConstructorHandle.Kind == HandleKind.MemberReference)
     {
         MemberReferenceHandle customAttributeConstructorReferenceHandle       = (MemberReferenceHandle)customAttributeConstructorHandle;
         MemberReference       customAttributeConstructorReference             = _module.MetadataReader.GetMemberReference(customAttributeConstructorReferenceHandle);
         EntityHandle          customAttributeConstructorReferenceParentHandle = customAttributeConstructorReference.Parent;
         if (customAttributeConstructorReferenceParentHandle.Kind == HandleKind.TypeReference)
         {
             TypeReferenceHandle customAttributeConstructorTypeReferenceHandle = (TypeReferenceHandle)customAttributeConstructorReferenceParentHandle;
             GetTypeNameFromTypeReferenceHandle(customAttributeConstructorTypeReferenceHandle, out customAttributeTypeNamespace, out customAttributeTypeName);
         }
         else
         {
             Debug.Assert(customAttributeConstructorReferenceParentHandle.Kind == HandleKind.TypeSpecification);
             TypeSpecificationHandle  customAttributeConstructorTypeSpecificationHandle = (TypeSpecificationHandle)customAttributeConstructorReferenceParentHandle;
             TypeSpecification        customAttributeConstructorTypeSpecification       = _module.MetadataReader.GetTypeSpecification(customAttributeConstructorTypeSpecificationHandle);
             FirstTypeHandleExtractor fakeSignatureTypeProvider = new FirstTypeHandleExtractor();
             customAttributeConstructorTypeSpecification.DecodeSignature(fakeSignatureTypeProvider, new DummyGenericContext());
             EntityHandle firstTypeHandle = fakeSignatureTypeProvider.FirstTypeHandle;
             if (firstTypeHandle.Kind == HandleKind.TypeDefinition)
             {
                 TypeDefinitionHandle customAttributeConstructorTypeDefinitionHandle = (TypeDefinitionHandle)firstTypeHandle;
                 GetTypeNameFromTypeDefinitionHandle(customAttributeConstructorTypeDefinitionHandle, out customAttributeTypeNamespace, out customAttributeTypeName);
             }
             else
             {
                 Debug.Assert(firstTypeHandle.Kind == HandleKind.TypeReference);
                 TypeReferenceHandle customAttributeConstructorTypeReferenceHandle = (TypeReferenceHandle)firstTypeHandle;
                 GetTypeNameFromTypeReferenceHandle(customAttributeConstructorTypeReferenceHandle, out customAttributeTypeNamespace, out customAttributeTypeName);
             }
         }
     }
     else
     {
         Debug.Assert(false);
         customAttributeTypeNamespace = null;
         customAttributeTypeName      = null;
     }
 }
        XSharpType ISignatureTypeProvider <XSharpType, object> .GetTypeFromSpecification(
            MetadataReader reader,
            object genericContext,
            TypeSpecificationHandle handle,
            byte rawTypeKind)
        {
            TypeSpecification typeSpec = _reader.GetTypeSpecification(handle);

            return(typeSpec.DecodeSignature(this, genericContext));
        }
Example #7
0
 public TypeSpecificationType(GenericContext gc, TypeSpecificationHandle handle) : base(gc.cx)
 {
     ts          = cx.mdReader.GetTypeSpecification(handle);
     decodedType = ts.DecodeSignature(cx.TypeSignatureDecoder, gc);
     ShortId     = decodedType.ShortId;
 }
Example #8
0
        IrisType ITypeProvider <IrisType> .GetTypeFromSpecification(MetadataReader reader, TypeSpecificationHandle handle, SignatureTypeHandleCode code)
        {
            TypeSpecification typeSpec = _reader.GetTypeSpecification(handle);

            return(typeSpec.DecodeSignature(this));
        }