Output: Correctly scope type parameters in class declarations

This commit is contained in:
Katy Coe
2020-02-06 01:46:31 +01:00
parent 7d88fd8fc4
commit 66b8e30586
2 changed files with 11 additions and 3 deletions

View File

@@ -554,11 +554,15 @@ namespace Il2CppInspector
sb.Append(prefix + type.GetModifierString()); sb.Append(prefix + type.GetModifierString());
var @base = type.ImplementedInterfaces.Select(x => x.GetScopedCSharpName(scope)).ToList(); // Inheriting from a base class or implementing an interface using a generic type which contains a nested type parameter
// inside the declared class must be referenced from outside the scope of the type being defined
var outerScope = new Scope {Current = scope.Current.DeclaringType, Namespaces = scope.Namespaces};
var @base = type.ImplementedInterfaces.Select(x => x.GetScopedCSharpName(outerScope)).ToList();
if (type.BaseType != null && type.BaseType.FullName != "System.Object" && type.BaseType.FullName != "System.ValueType" && !type.IsEnum) if (type.BaseType != null && type.BaseType.FullName != "System.Object" && type.BaseType.FullName != "System.ValueType" && !type.IsEnum)
@base.Insert(0, type.BaseType.GetScopedCSharpName(scope)); @base.Insert(0, type.BaseType.GetScopedCSharpName(outerScope));
if (type.IsEnum && type.GetEnumUnderlyingType().FullName != "System.Int32") // enums derive from int by default if (type.IsEnum && type.GetEnumUnderlyingType().FullName != "System.Int32") // enums derive from int by default
@base.Insert(0, type.GetEnumUnderlyingType().GetScopedCSharpName(scope)); @base.Insert(0, type.GetEnumUnderlyingType().GetScopedCSharpName(outerScope));
var baseText = @base.Count > 0 ? " : " + string.Join(", ", @base) : string.Empty; var baseText = @base.Count > 0 ? " : " + string.Join(", ", @base) : string.Empty;
sb.Append($"{type.CSharpTypeDeclarationName}{baseText}"); sb.Append($"{type.CSharpTypeDeclarationName}{baseText}");

View File

@@ -294,6 +294,10 @@ namespace Il2CppInspector.Reflection {
if (usingScope == null) if (usingScope == null)
return CSharpName; return CSharpName;
// Generic parameters don't have a scope
if (IsGenericParameter)
return CSharpName;
var s = Namespace + "." + base.Name; var s = Namespace + "." + base.Name;
// Built-in keyword type names do not require a scope // Built-in keyword type names do not require a scope