Output: Handle indexers correctly
This commit is contained in:
@@ -212,8 +212,16 @@ namespace Il2CppInspector
|
|||||||
var getAccess = (prop.GetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask;
|
var getAccess = (prop.GetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask;
|
||||||
var setAccess = (prop.SetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask;
|
var setAccess = (prop.SetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask;
|
||||||
|
|
||||||
string modifiers = getAccess > setAccess? prop.GetMethod.GetModifierString() : prop.SetMethod.GetModifierString();
|
var primary = getAccess >= setAccess ? prop.GetMethod : prop.SetMethod;
|
||||||
writer.Write($"{prefix}\t{modifiers}{prop.PropertyType.CSharpName} {prop.Name} {{ ");
|
writer.Write($"{prefix}\t{primary.GetModifierString()}{prop.PropertyType.CSharpName} ");
|
||||||
|
|
||||||
|
// Non-indexer
|
||||||
|
if ((!prop.CanRead || !prop.GetMethod.DeclaredParameters.Any()) && (!prop.CanWrite || prop.SetMethod.DeclaredParameters.Count == 1))
|
||||||
|
writer.Write($"{prop.Name} {{ ");
|
||||||
|
// Indexer
|
||||||
|
else
|
||||||
|
writer.Write("this[" + string.Join(", ", primary.DeclaredParameters.SkipLast(getAccess > setAccess? 0 : 1).Select(p => p.GetParameterString())) + "] { ");
|
||||||
|
|
||||||
writer.Write((prop.CanRead? prop.GetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true)
|
writer.Write((prop.CanRead? prop.GetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true)
|
||||||
+ (getAccess < setAccess? prop.GetMethod.GetAccessModifierString() : "") + "get; " : "")
|
+ (getAccess < setAccess? prop.GetMethod.GetAccessModifierString() : "") + "get; " : "")
|
||||||
+ (prop.CanWrite? prop.SetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true)
|
+ (prop.CanWrite? prop.SetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
|
|
||||||
public override string Name { get; protected set; }
|
public override string Name { get; protected set; }
|
||||||
|
|
||||||
public TypeInfo PropertyType => GetMethod?.ReturnType ?? SetMethod.DeclaredParameters[0].ParameterType;
|
public TypeInfo PropertyType => GetMethod?.ReturnType ?? SetMethod.DeclaredParameters[^1].ParameterType;
|
||||||
|
|
||||||
public override MemberTypes MemberType => MemberTypes.Property;
|
public override MemberTypes MemberType => MemberTypes.Property;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user