public static string GetFullName(this TypeSpecificationHandle typeSpecHandle, MetadataReader reader)
        {
            var typeSpec = typeSpecHandle.GetTypeSpecification(reader);

            if (typeSpec.Signature.IsNull(reader))
            {
                return(null);
            }

            return(typeSpec.Signature.GetFullName(reader));
        }
Exemple #2
0
        //
        // Main routine to parse a metadata type specification signature.
        //
        private static RuntimeTypeInfo?TryResolveTypeSignature(this TypeSpecificationHandle typeSpecHandle, MetadataReader reader, TypeContext typeContext, ref Exception?exception)
        {
            Handle typeHandle = typeSpecHandle.GetTypeSpecification(reader).Signature;

            switch (typeHandle.HandleType)
            {
            case HandleType.ArraySignature:
            {
                ArraySignature sig  = typeHandle.ToArraySignatureHandle(reader).GetArraySignature(reader);
                int            rank = sig.Rank;
                if (rank <= 0)
                {
                    throw new BadImageFormatException();         // Bad rank.
                }
                RuntimeTypeInfo?elementType = sig.ElementType.TryResolve(reader, typeContext, ref exception);
                if (elementType == null)
                {
                    return(null);
                }
                return(elementType.GetMultiDimArrayType(rank));
            }

            case HandleType.ByReferenceSignature:
            {
                ByReferenceSignature sig        = typeHandle.ToByReferenceSignatureHandle(reader).GetByReferenceSignature(reader);
                RuntimeTypeInfo?     targetType = sig.Type.TryResolve(reader, typeContext, ref exception);
                if (targetType == null)
                {
                    return(null);
                }
                return(targetType.GetByRefType());
            }

            case HandleType.MethodTypeVariableSignature:
            {
                MethodTypeVariableSignature sig = typeHandle.ToMethodTypeVariableSignatureHandle(reader).GetMethodTypeVariableSignature(reader);
                return(typeContext.GenericMethodArguments[sig.Number]);
            }

            case HandleType.PointerSignature:
            {
                PointerSignature sig        = typeHandle.ToPointerSignatureHandle(reader).GetPointerSignature(reader);
                RuntimeTypeInfo? targetType = sig.Type.TryResolve(reader, typeContext, ref exception);
                if (targetType == null)
                {
                    return(null);
                }
                return(targetType.GetPointerType());
            }

            case HandleType.SZArraySignature:
            {
                SZArraySignature sig         = typeHandle.ToSZArraySignatureHandle(reader).GetSZArraySignature(reader);
                RuntimeTypeInfo? elementType = sig.ElementType.TryResolve(reader, typeContext, ref exception);
                if (elementType == null)
                {
                    return(null);
                }
                return(elementType.GetArrayType());
            }

            case HandleType.TypeDefinition:
            {
                return(typeHandle.ToTypeDefinitionHandle(reader).ResolveTypeDefinition(reader));
            }

            case HandleType.TypeInstantiationSignature:
            {
                TypeInstantiationSignature sig = typeHandle.ToTypeInstantiationSignatureHandle(reader).GetTypeInstantiationSignature(reader);
                RuntimeTypeInfo?           genericTypeDefinition = sig.GenericType.TryResolve(reader, typeContext, ref exception);
                if (genericTypeDefinition == null)
                {
                    return(null);
                }
                LowLevelList <RuntimeTypeInfo> genericTypeArguments = new LowLevelList <RuntimeTypeInfo>();
                foreach (Handle genericTypeArgumentHandle in sig.GenericTypeArguments)
                {
                    RuntimeTypeInfo?genericTypeArgument = genericTypeArgumentHandle.TryResolve(reader, typeContext, ref exception);
                    if (genericTypeArgument == null)
                    {
                        return(null);
                    }
                    genericTypeArguments.Add(genericTypeArgument);
                }
                return(genericTypeDefinition.GetConstructedGenericType(genericTypeArguments.ToArray()));
            }

            case HandleType.TypeReference:
            {
                return(typeHandle.ToTypeReferenceHandle(reader).TryResolveTypeReference(reader, ref exception));
            }

            case HandleType.TypeVariableSignature:
            {
                TypeVariableSignature sig = typeHandle.ToTypeVariableSignatureHandle(reader).GetTypeVariableSignature(reader);
                return(typeContext.GenericTypeArguments[sig.Number]);
            }

            default:
                throw new NotSupportedException();     // Unexpected Type signature type.
            }
        }
Exemple #3
0
        //
        // Main routine to parse a metadata type specification signature.
        //
        private static RuntimeType TryResolveTypeSignature(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeSpecificationHandle typeSpecHandle, TypeContext typeContext, ref Exception exception)
        {
            Handle typeHandle = typeSpecHandle.GetTypeSpecification(reader).Signature;
            switch (typeHandle.HandleType)
            {
                case HandleType.ArraySignature:
                    {
                        ArraySignature sig = typeHandle.ToArraySignatureHandle(reader).GetArraySignature(reader);
                        int rank = sig.Rank;
                        if (rank <= 0)
                            throw new BadImageFormatException(); // Bad rank.
                        RuntimeType elementType = reflectionDomain.TryResolve(reader, sig.ElementType, typeContext, ref exception);
                        if (elementType == null)
                            return null;
                        return ReflectionCoreNonPortable.GetMultiDimArrayType(elementType, rank);
                    }

                case HandleType.ByReferenceSignature:
                    {
                        ByReferenceSignature sig = typeHandle.ToByReferenceSignatureHandle(reader).GetByReferenceSignature(reader);
                        RuntimeType targetType = reflectionDomain.TryResolve(reader, sig.Type, typeContext, ref exception);
                        if (targetType == null)
                            return null;
                        return ReflectionCoreNonPortable.GetByRefType(targetType);
                    }

                case HandleType.MethodTypeVariableSignature:
                    {
                        MethodTypeVariableSignature sig = typeHandle.ToMethodTypeVariableSignatureHandle(reader).GetMethodTypeVariableSignature(reader);
                        return typeContext.GenericMethodArguments[sig.Number];
                    }

                case HandleType.PointerSignature:
                    {
                        PointerSignature sig = typeHandle.ToPointerSignatureHandle(reader).GetPointerSignature(reader);
                        RuntimeType targetType = reflectionDomain.TryResolve(reader, sig.Type, typeContext, ref exception);
                        if (targetType == null)
                            return null;
                        return ReflectionCoreNonPortable.GetPointerType(targetType);
                    }

                case HandleType.SZArraySignature:
                    {
                        SZArraySignature sig = typeHandle.ToSZArraySignatureHandle(reader).GetSZArraySignature(reader);
                        RuntimeType elementType = reflectionDomain.TryResolve(reader, sig.ElementType, typeContext, ref exception);
                        if (elementType == null)
                            return null;
                        return ReflectionCoreNonPortable.GetArrayType(elementType);
                    }

                case HandleType.TypeDefinition:
                    {
                        return reflectionDomain.ResolveTypeDefinition(reader, typeHandle.ToTypeDefinitionHandle(reader));
                    }

                case HandleType.TypeInstantiationSignature:
                    {
                        TypeInstantiationSignature sig = typeHandle.ToTypeInstantiationSignatureHandle(reader).GetTypeInstantiationSignature(reader);
                        RuntimeType genericTypeDefinition = reflectionDomain.TryResolve(reader, sig.GenericType, typeContext, ref exception);
                        if (genericTypeDefinition == null)
                            return null;
                        LowLevelList<RuntimeType> genericTypeArguments = new LowLevelList<RuntimeType>();
                        foreach (Handle genericTypeArgumentHandle in sig.GenericTypeArguments)
                        {
                            RuntimeType genericTypeArgument = reflectionDomain.TryResolve(reader, genericTypeArgumentHandle, typeContext, ref exception);
                            if (genericTypeArgument == null)
                                return null;
                            genericTypeArguments.Add(genericTypeArgument);
                        }
                        return ReflectionCoreNonPortable.GetConstructedGenericType(genericTypeDefinition, genericTypeArguments.ToArray());
                    }

                case HandleType.TypeReference:
                    {
                        return reflectionDomain.TryResolveTypeReference(reader, typeHandle.ToTypeReferenceHandle(reader), ref exception);
                    }

                case HandleType.TypeVariableSignature:
                    {
                        TypeVariableSignature sig = typeHandle.ToTypeVariableSignatureHandle(reader).GetTypeVariableSignature(reader);
                        return typeContext.GenericTypeArguments[sig.Number];
                    }

                default:
                    throw new NotSupportedException(); // Unexpected Type signature type.
            }
        }