Output: Correctly scope type parameters in class declarations
This commit is contained in:
@@ -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}");
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user