From f08cfd573ccb8680849cec5b394f389bbaa0d071 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Fri, 14 Aug 2020 03:20:56 +0200 Subject: [PATCH] C#: Output DefaultMemberAttribute if the type doesn't have an indexer --- Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs b/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs index c1386c0..fefa81e 100644 --- a/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs +++ b/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs @@ -406,6 +406,7 @@ namespace Il2CppInspector.Outputs // Properties sb.Clear(); + var hasIndexer = false; foreach (var prop in type.DeclaredProperties) { // Attributes sb.Append(prop.CustomAttributes.OrderBy(a => a.AttributeType.Name) @@ -435,6 +436,7 @@ namespace Il2CppInspector.Outputs .Select(p => p.GetParameterString(scope, !SuppressMetadata, MustCompile))) + "] { "); getBody = " => default;"; setBody = " {}"; + hasIndexer = true; } sb.Append((prop.CanRead? prop.GetMethod.CustomAttributes.Where(a => !MustCompile || a.AttributeType.FullName != CGAttribute) @@ -554,9 +556,9 @@ namespace Il2CppInspector.Outputs if (type.IsSerializable) sb.Append(prefix + "[Serializable]\n"); - // TODO: DefaultMemberAttribute should be output if it is present and the type does not have an indexer, otherwise suppressed + // DefaultMemberAttribute should be output if it is present and the type does not have an indexer, otherwise suppressed // See https://docs.microsoft.com/en-us/dotnet/api/system.reflection.defaultmemberattribute?view=netframework-4.8 - sb.Append(type.CustomAttributes.Where(a => a.AttributeType.FullName != DMAttribute && a.AttributeType.FullName != ExtAttribute) + sb.Append(type.CustomAttributes.Where(a => (a.AttributeType.FullName != DMAttribute || !hasIndexer) && a.AttributeType.FullName != ExtAttribute) .OrderBy(a => a.AttributeType.Name).ToString(scope, prefix, emitPointer: !SuppressMetadata, mustCompile: MustCompile)); // Roll-up multicast delegates to use the 'delegate' syntactic sugar