From bdb9f7935b5d08142954746dc4e6bff0c71d7a34 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sun, 9 Aug 2020 19:24:41 +0200 Subject: [PATCH] Model: Allow null namespace list in Scope for getScopedFullName() --- Il2CppInspector.Common/Reflection/TypeInfo.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Il2CppInspector.Common/Reflection/TypeInfo.cs b/Il2CppInspector.Common/Reflection/TypeInfo.cs index 1d1d39f..a5d2a40 100644 --- a/Il2CppInspector.Common/Reflection/TypeInfo.cs +++ b/Il2CppInspector.Common/Reflection/TypeInfo.cs @@ -459,7 +459,7 @@ namespace Il2CppInspector.Reflection // Check to see if there is a namespace in our using directives which brings this type into scope // Sort by descending order of length to search the deepest namespaces first - : scope.Namespaces.OrderByDescending(n => n.Length).FirstOrDefault(n => declaringScope == n || declaringScope.StartsWith(n + ".")); + : scope.Namespaces?.OrderByDescending(n => n.Length).FirstOrDefault(n => declaringScope == n || declaringScope.StartsWith(n + ".")); // minimallyScopedName will eventually contain the least qualified name needed to access the type // Initially we set it as follows: @@ -522,7 +522,8 @@ namespace Il2CppInspector.Reflection outerTypeName = minimallyScopedName.Split('.')[0]; // Take matching type names from all namespaces in scope - var matchingNamespaces = scope.Namespaces.Where(n => Assembly.Model.TypesByFullName.ContainsKey(n + "." + outerTypeName)).ToList(); + var matchingNamespaces = scope.Namespaces? + .Where(n => Assembly.Model.TypesByFullName.ContainsKey(n + "." + outerTypeName)).ToList() ?? new List(); // The global namespace is in scope so take every matching type from that too if (Assembly.Model.TypesByFullName.ContainsKey(outerTypeName)) @@ -542,7 +543,8 @@ namespace Il2CppInspector.Reflection // Finally, check if the selected name has ambiguity with any available namespaces in the current scope // If so, use the full name with the mutual root scope cut off from the start - var checkNamespaces = scope.Namespaces.Select(ns => (!string.IsNullOrEmpty(ns)? ns + "." : "") + minimallyScopedName).ToList(); + var checkNamespaces = scope.Namespaces? + .Select(ns => (!string.IsNullOrEmpty(ns)? ns + "." : "") + minimallyScopedName).ToList() ?? new List(); if (Assembly.Model.Namespaces.Intersect(checkNamespaces).Any()) minimallyScopedName = mutualRootScope.Length > 0 ? usedType.Substring(mutualRootScope.Length + 1) : usedType;