Beispiel #1
0
        private TType DecodeTypeHandle(ref BlobReader blobReader, byte rawTypeKind, bool allowTypeSpecifications)
        {
            EntityHandle handle = blobReader.ReadTypeHandle();

            if (!handle.IsNil)
            {
                switch (handle.Kind)
                {
                case HandleKind.TypeDefinition:
                    return(_provider.GetTypeFromDefinition(_metadataReaderOpt, (TypeDefinitionHandle)handle, rawTypeKind));

                case HandleKind.TypeReference:
                    return(_provider.GetTypeFromReference(_metadataReaderOpt, (TypeReferenceHandle)handle, rawTypeKind));

                case HandleKind.TypeSpecification:
                    if (!allowTypeSpecifications)
                    {
                        // To prevent cycles, the token following (CLASS | VALUETYPE) must not be a type spec.
                        // https://github.com/dotnet/coreclr/blob/8ff2389204d7c41b17eff0e9536267aea8d6496f/src/md/compiler/mdvalidator.cpp#L6154-L6160
                        throw new BadImageFormatException(SR.NotTypeDefOrRefHandle);
                    }

                    return(_provider.GetTypeFromSpecification(_metadataReaderOpt, _genericContext, (TypeSpecificationHandle)handle, rawTypeKind));

                default:
                    // indicates an error returned from ReadTypeHandle, otherwise unreachable.
                    Debug.Assert(handle.IsNil);     // will fall through to throw in release.
                    break;
                }
            }

            throw new BadImageFormatException(SR.NotTypeDefOrRefOrSpecHandle);
        }
Beispiel #2
0
        private TType DecodeTypeHandle(ref BlobReader blobReader, SignatureTypeHandleCode code, bool alllowTypeSpecifications)
        {
            // Force no differentiation of class vs. value type unless the option is enabled.
            // Avoids cost of WinRT projection.
            if ((_options & SignatureDecoderOptions.DifferentiateClassAndValueTypes) == 0)
            {
                code = SignatureTypeHandleCode.Unresolved;
            }

            EntityHandle handle = blobReader.ReadTypeHandle();

            if (!handle.IsNil)
            {
                switch (handle.Kind)
                {
                case HandleKind.TypeDefinition:
                    var typeDef = (TypeDefinitionHandle)handle;
                    return(_provider.GetTypeFromDefinition(_metadataReaderOpt, typeDef, code));

                case HandleKind.TypeReference:
                    var typeRef = (TypeReferenceHandle)handle;
                    if (code != SignatureTypeHandleCode.Unresolved)
                    {
                        ProjectClassOrValueType(typeRef, ref code);
                    }
                    return(_provider.GetTypeFromReference(_metadataReaderOpt, typeRef, code));

                case HandleKind.TypeSpecification:
                    if (!alllowTypeSpecifications)
                    {
                        // To prevent cycles, the token following (CLASS | VALUETYPE) must not be a type spec.
                        // https://github.com/dotnet/coreclr/blob/8ff2389204d7c41b17eff0e9536267aea8d6496f/src/md/compiler/mdvalidator.cpp#L6154-L6160
                        throw new BadImageFormatException(SR.NotTypeDefOrRefHandle);
                    }

                    if (code != SignatureTypeHandleCode.Unresolved)
                    {
                        // TODO: We need more work here in differentiating case because instantiations can project class
                        // to value type as in IReference<T> -> Nullable<T>. Unblocking Roslyn work where the differentiation
                        // feature is not used. Note that the use-case of custom-mods will not hit this because there is no
                        // CLASS | VALUETYPE before the modifier token and so it always comes in unresolved.
                        code = SignatureTypeHandleCode.Unresolved;     // never lie in the meantime.
                    }

                    var typeSpec = (TypeSpecificationHandle)handle;
                    return(_provider.GetTypeFromSpecification(_metadataReaderOpt, typeSpec, SignatureTypeHandleCode.Unresolved));

                default:
                    // indicates an error returned from ReadTypeHandle, otherwise unreachable.
                    Debug.Assert(handle.IsNil);     // will fall through to throw in release.
                    break;
                }
            }

            throw new BadImageFormatException(SR.NotTypeDefOrRefOrSpecHandle);
        }
Beispiel #3
0
 public RoType GetTypeFromSpecification(MetadataReader reader, TypeContext genericContext, TypeSpecificationHandle handle, byte rawTypeKind) => _typeProvider.GetTypeFromSpecification(reader, genericContext, handle, rawTypeKind);