CS: Fix "Namespace used like type" (CS0118) (needs additional work)
This commit is contained in:
@@ -16,6 +16,9 @@ namespace Il2CppInspector.Reflection
|
||||
public Il2CppInspector Package { get; }
|
||||
public List<Assembly> Assemblies { get; } = new List<Assembly>();
|
||||
|
||||
// List of all namespaces defined by the application
|
||||
public List<string> Namespaces { get; }
|
||||
|
||||
// List of all types from TypeDefs ordered by their TypeDefinitionIndex
|
||||
public TypeInfo[] TypesByDefinitionIndex { get; }
|
||||
|
||||
@@ -113,6 +116,9 @@ namespace Il2CppInspector.Reflection
|
||||
GenericMethods[spec] = method;
|
||||
}
|
||||
|
||||
// Generate a list of all namespaces used
|
||||
Namespaces = Assemblies.SelectMany(x => x.DefinedTypes).GroupBy(t => t.Namespace).Select(n => n.Key).Distinct().ToList();
|
||||
|
||||
// Find all custom attribute generators (populate AttributesByIndices) (use ToList() to force evaluation)
|
||||
var allAssemblyAttributes = Assemblies.Select(a => a.CustomAttributes).ToList();
|
||||
var allTypeAttributes = TypesByDefinitionIndex.Select(t => t.CustomAttributes).ToList();
|
||||
|
||||
@@ -524,6 +524,27 @@ namespace Il2CppInspector.Reflection
|
||||
if (matchingNamespaces.Count == 0 && !hidden && string.IsNullOrEmpty(mutualRootScope) && usingDirective == null)
|
||||
minimallyScopedName = usedType;
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
if (Assembly.Model.Namespaces.Intersect(checkNamespaces).Any())
|
||||
minimallyScopedName = mutualRootScope.Length > 0 ? usedType.Substring(mutualRootScope.Length + 1) : usedType;
|
||||
|
||||
// Check current namespace and all ancestors too
|
||||
else {
|
||||
checkNamespaces.Clear();
|
||||
var ancestorUsingScope = "." + usingScope;
|
||||
while (ancestorUsingScope.IndexOf(".", StringComparison.Ordinal) != -1) {
|
||||
ancestorUsingScope = ancestorUsingScope.Substring(0, ancestorUsingScope.LastIndexOf(".", StringComparison.Ordinal));
|
||||
checkNamespaces.Add((ancestorUsingScope.Length > 0 ? ancestorUsingScope.Substring(1) + "." : "") + minimallyScopedName);
|
||||
}
|
||||
|
||||
if (Assembly.Model.Namespaces.Intersect(checkNamespaces).Any())
|
||||
minimallyScopedName = mutualRootScope.Length > 0 ? usedType.Substring(mutualRootScope.Length + 1) : "global::" + usedType;
|
||||
}
|
||||
|
||||
return minimallyScopedName;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user