diff --git a/src/Draco.Compiler/Internal/Symbols/Metadata/TypeProvider.cs b/src/Draco.Compiler/Internal/Symbols/Metadata/TypeProvider.cs index 2923c1fd2..d9cab6d92 100644 --- a/src/Draco.Compiler/Internal/Symbols/Metadata/TypeProvider.cs +++ b/src/Draco.Compiler/Internal/Symbols/Metadata/TypeProvider.cs @@ -141,28 +141,33 @@ public TypeSymbol GetTypeFromReference(MetadataReader reader, TypeReferenceHandl var key = new CacheKey(reader, handle); if (!this.cache.TryGetValue(key, out var type)) { - var parts = new List(); - var reference = reader.GetTypeReference(handle); - parts.Add(reader.GetString(reference.Name)); - EntityHandle resolutionScope; - for (resolutionScope = reference.ResolutionScope; resolutionScope.Kind == HandleKind.TypeReference; resolutionScope = reference.ResolutionScope) - { - reference = reader.GetTypeReference((TypeReferenceHandle)resolutionScope); - parts.Add(reader.GetString(reference.Name)); - } - var @namespace = reader.GetString(reference.Namespace); - if (!string.IsNullOrEmpty(@namespace)) parts.AddRange(@namespace.Split('.').Reverse()); - parts.Reverse(); - - // TODO: If we don't have the assembly report error - var assemblyName = reader.GetAssemblyReference((AssemblyReferenceHandle)resolutionScope).GetAssemblyName(); - var assembly = this.compilation.MetadataAssemblies.Values.Single(x => x.AssemblyName.FullName == assemblyName.FullName); - type = assembly.RootNamespace.Lookup(parts.ToImmutableArray()).OfType().Single(); + type = this.BuildTypeFromReference(reader, handle, rawTypeKind); this.cache.Add(key, type); } return type; } + private TypeSymbol BuildTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) + { + var parts = new List(); + var reference = reader.GetTypeReference(handle); + parts.Add(reader.GetString(reference.Name)); + EntityHandle resolutionScope; + for (resolutionScope = reference.ResolutionScope; resolutionScope.Kind == HandleKind.TypeReference; resolutionScope = reference.ResolutionScope) + { + reference = reader.GetTypeReference((TypeReferenceHandle)resolutionScope); + parts.Add(reader.GetString(reference.Name)); + } + var @namespace = reader.GetString(reference.Namespace); + if (!string.IsNullOrEmpty(@namespace)) parts.AddRange(@namespace.Split('.').Reverse()); + parts.Reverse(); + + // TODO: If we don't have the assembly report error + var assemblyName = reader.GetAssemblyReference((AssemblyReferenceHandle)resolutionScope).GetAssemblyName(); + var assembly = this.compilation.MetadataAssemblies.Values.Single(x => x.AssemblyName.FullName == assemblyName.FullName); + return assembly.RootNamespace.Lookup(parts.ToImmutableArray()).OfType().Single(); + } + // TODO: Should we cache this as well? doesn't seem to have any effect public TypeSymbol GetTypeFromSpecification(MetadataReader reader, Symbol genericContext, TypeSpecificationHandle handle, byte rawTypeKind) {