Output: Handle indexers correctly

This commit is contained in:
Katy Coe
2019-11-09 23:46:07 +01:00
parent d1cfa46775
commit 7f683fc629
2 changed files with 11 additions and 3 deletions

View File

@@ -212,8 +212,16 @@ namespace Il2CppInspector
var getAccess = (prop.GetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask;
var setAccess = (prop.SetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask;
string modifiers = getAccess > setAccess? prop.GetMethod.GetModifierString() : prop.SetMethod.GetModifierString();
writer.Write($"{prefix}\t{modifiers}{prop.PropertyType.CSharpName} {prop.Name} {{ ");
var primary = getAccess >= setAccess ? prop.GetMethod : prop.SetMethod;
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)
+ (getAccess < setAccess? prop.GetMethod.GetAccessModifierString() : "") + "get; " : "")
+ (prop.CanWrite? prop.SetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true)

View File

@@ -26,7 +26,7 @@ namespace Il2CppInspector.Reflection {
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;