diff --git a/reflect/Reader/ModuleReader.cs b/reflect/Reader/ModuleReader.cs index 7a717284..d53cf889 100644 --- a/reflect/Reader/ModuleReader.cs +++ b/reflect/Reader/ModuleReader.cs @@ -374,7 +374,8 @@ namespace IKVM.Reflection.Reader case TypeRefTable.Index: { Type outer = ResolveType(scope, null); - typeRefs[index] = outer.GetNestedType(GetString(TypeRef.records[index].TypeName), BindingFlags.Public | BindingFlags.NonPublic); + string typeName = GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName); + typeRefs[index] = outer.GetNestedTypeCorrectly(typeName); break; } case ModuleTable.Index: diff --git a/reflect/Type.cs b/reflect/Type.cs index 8f8d9c7e..6d0caae7 100644 --- a/reflect/Type.cs +++ b/reflect/Type.cs @@ -747,6 +747,38 @@ namespace IKVM.Reflection return GetConstructor(bindingAttr, binder, types, modifiers); } + private static bool MatchTypeNames(string ns, string name, string fullName) + { + if (ns == null) + { + return name == fullName; + } + else if (ns.Length + 1 + name.Length == fullName.Length) + { + return fullName[ns.Length] == '.' + && String.CompareOrdinal(ns, 0, fullName, 0, ns.Length) == 0 + && String.CompareOrdinal(name, 0, fullName, ns.Length + 1, name.Length) == 0; + } + else + { + return false; + } + } + + // unlike the public API, this takes the namespace and name into account + internal Type GetNestedTypeCorrectly(string name) + { + CheckBaked(); + foreach (Type type in __GetDeclaredTypes()) + { + if (MatchTypeNames(type.__Namespace, type.__Name, name)) + { + return type; + } + } + return null; + } + public Type GetNestedType(string name) { return GetNestedType(name, BindingFlags.Public); diff --git a/reflect/TypeNameParser.cs b/reflect/TypeNameParser.cs index d6c18ee9..77686f03 100644 --- a/reflect/TypeNameParser.cs +++ b/reflect/TypeNameParser.cs @@ -407,7 +407,7 @@ namespace IKVM.Reflection { foreach (string nest in nested) { - type = type.GetNestedType(nest, BindingFlags.Public | BindingFlags.NonPublic); + type = type.GetNestedTypeCorrectly(TypeNameParser.Unescape(nest)); if (type == null) { if (throwOnError)