public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result) { result = null; RuntimeType elementType; Exception typeLoadException = ElementTypeName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out elementType); if (typeLoadException != null) { return(typeLoadException); } result = ReflectionCoreNonPortable.GetPointerType(elementType); return(null); }
// // 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. } }