Output: Fix covariant/contravariant generic constraints and nested generic parameters in type definitions
This commit is contained in:
@@ -54,6 +54,10 @@ namespace Il2CppInspector.Reflection {
|
|||||||
n = GenericTypeArguments[0].CSharpName + "?";
|
n = GenericTypeArguments[0].CSharpName + "?";
|
||||||
if (HasElementType)
|
if (HasElementType)
|
||||||
n = ElementType.CSharpName;
|
n = ElementType.CSharpName;
|
||||||
|
if ((GenericParameterAttributes & GenericParameterAttributes.Covariant) == GenericParameterAttributes.Covariant)
|
||||||
|
n = "out " + n;
|
||||||
|
if ((GenericParameterAttributes & GenericParameterAttributes.Contravariant) == GenericParameterAttributes.Contravariant)
|
||||||
|
n = "in " + n;
|
||||||
return n + (IsArray ? "[" + new string(',', GetArrayRank() - 1) + "]" : "") + (IsPointer ? "*" : "");
|
return n + (IsArray ? "[" + new string(',', GetArrayRank() - 1) + "]" : "") + (IsPointer ? "*" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,9 +66,11 @@ namespace Il2CppInspector.Reflection {
|
|||||||
public string CSharpTypeDeclarationName =>
|
public string CSharpTypeDeclarationName =>
|
||||||
(HasElementType?
|
(HasElementType?
|
||||||
ElementType.CSharpTypeDeclarationName :
|
ElementType.CSharpTypeDeclarationName :
|
||||||
base.Name.IndexOf("`", StringComparison.Ordinal) == -1 ? base.Name : base.Name.Remove(base.Name.IndexOf("`", StringComparison.Ordinal))
|
((GenericParameterAttributes & GenericParameterAttributes.Contravariant) == GenericParameterAttributes.Contravariant? "in " : "")
|
||||||
+ (GenericTypeParameters != null ? "<" + string.Join(", ", GenericTypeParameters.Select(x => x.Name)) + ">" : "")
|
+ ((GenericParameterAttributes & GenericParameterAttributes.Covariant) == GenericParameterAttributes.Covariant? "out ":"")
|
||||||
+ (GenericTypeArguments != null ? "<" + string.Join(", ", GenericTypeArguments.Select(x => x.Name)) + ">" : ""))
|
+ (base.Name.IndexOf("`", StringComparison.Ordinal) == -1 ? base.Name : base.Name.Remove(base.Name.IndexOf("`", StringComparison.Ordinal)))
|
||||||
|
+ (GenericTypeParameters != null ? "<" + string.Join(", ", GenericTypeParameters.Select(x => x.CSharpTypeDeclarationName)) + ">" : "")
|
||||||
|
+ (GenericTypeArguments != null ? "<" + string.Join(", ", GenericTypeArguments.Select(x => x.CSharpTypeDeclarationName)) + ">" : ""))
|
||||||
+ (IsArray ? "[" + new string(',', GetArrayRank() - 1) + "]" : "")
|
+ (IsArray ? "[" + new string(',', GetArrayRank() - 1) + "]" : "")
|
||||||
+ (IsPointer ? "*" : "");
|
+ (IsPointer ? "*" : "");
|
||||||
|
|
||||||
@@ -728,6 +734,10 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// new() must be the last constraint specified
|
// new() must be the last constraint specified
|
||||||
constraintList.Add("new()");
|
constraintList.Add("new()");
|
||||||
|
|
||||||
|
// Covariance/contravariance constraints can lead to an empty constraint list
|
||||||
|
if (!constraintList.Any())
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
return "where " + Name + " : " + string.Join(", ", constraintList);
|
return "where " + Name + " : " + string.Join(", ", constraintList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user