From d8befc0a1549ad309c00e0f361f2ef6edf80ad60 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 10 Dec 2019 15:29:10 +0100 Subject: [PATCH] Output: Give non-auto-properties accessor bodies (CS8080) --- Il2CppDumper/Il2CppCSharpDumper.cs | 8 +++++--- Il2CppDumper/Program.cs | 2 +- Il2CppInspector/Reflection/PropertyInfo.cs | 2 ++ README.md | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Il2CppDumper/Il2CppCSharpDumper.cs b/Il2CppDumper/Il2CppCSharpDumper.cs index 2e1241a..a2b50b4 100644 --- a/Il2CppDumper/Il2CppCSharpDumper.cs +++ b/Il2CppDumper/Il2CppCSharpDumper.cs @@ -261,9 +261,11 @@ namespace Il2CppInspector var primary = getAccess >= setAccess ? prop.GetMethod : prop.SetMethod; sb.Append($"{prefix}\t{primary.GetModifierString()}{prop.PropertyType.GetScopedCSharpName(scope)} "); - // Non-indexer - var getBody = ";"; - var setBody = ";"; + // Non-indexer; non-auto-properties should have a body + var needsBody = MustCompile && !type.IsInterface && !type.IsAbstract && !prop.IsAutoProperty; + + var getBody = needsBody? " => default;" : ";"; + var setBody = needsBody? " {}" : ";"; if ((!prop.CanRead || !prop.GetMethod.DeclaredParameters.Any()) && (!prop.CanWrite || prop.SetMethod.DeclaredParameters.Count == 1)) sb.Append($"{prop.CSharpName} {{ "); diff --git a/Il2CppDumper/Program.cs b/Il2CppDumper/Program.cs index 281963b..a4dfc0b 100644 --- a/Il2CppDumper/Program.cs +++ b/Il2CppDumper/Program.cs @@ -49,7 +49,7 @@ namespace Il2CppInspector [Option('n', "suppress-metadata", Required = false, HelpText = "Diff tidying: suppress method pointers, field offsets and type indices from C# output. Useful for comparing two versions of a binary for changes with a diff tool")] public bool SuppressMetadata { get; set; } - [Option('k', "must-compile", Required = false, HelpText = "Compilation tidying: try really hard to make code that compiles. Suppress generation of code for items with CompilerGenerated attribute. Comment out attributes without parameterless constructors or all-optional constructor arguments. Don't emit add/remove/raise on events. Specify AttributeTargets.All on classes with AttributeUsage attribute. Force auto-properties to have get accessors.")] + [Option('k', "must-compile", Required = false, HelpText = "Compilation tidying: try really hard to make code that compiles. Suppress generation of code for items with CompilerGenerated attribute. Comment out attributes without parameterless constructors or all-optional constructor arguments. Don't emit add/remove/raise on events. Specify AttributeTargets.All on classes with AttributeUsage attribute. Force auto-properties to have get accessors. Force regular properties to have bodies.")] public bool MustCompile { get; set; } } diff --git a/Il2CppInspector/Reflection/PropertyInfo.cs b/Il2CppInspector/Reflection/PropertyInfo.cs index 33ec170..8c3e0a8 100644 --- a/Il2CppInspector/Reflection/PropertyInfo.cs +++ b/Il2CppInspector/Reflection/PropertyInfo.cs @@ -24,6 +24,8 @@ namespace Il2CppInspector.Reflection { public MethodInfo GetMethod { get; } public MethodInfo SetMethod { get; } + public bool IsAutoProperty => DeclaringType.DeclaredFields.Any(f => f.Name == $"<{Name}>k__BackingField"); + public override string Name { get; protected set; } public string CSharpName => diff --git a/README.md b/README.md index 530369f..47c48da 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ File format and architecture are automatically detected. -s, --sort (Default: index) Sort order of type definitions in C# output ('index' = by type definition index, 'name' = by type name). No effect when using file-per-class layout -f, --flatten Flatten the namespace hierarchy into a single folder rather than using per-namespace subfolders. Only used when layout is per-namespace or per-class -n, --suppress-metadata Diff tidying: suppress method pointers, field offsets and type indices from C# output. Useful for comparing two versions of a binary for changes with a diff tool - -k, --must-compile Compilation tidying: try really hard to make code that compiles. Suppress generation of code for items with CompilerGenerated attribute. Comment out attributes without parameterless constructors or all-optional constructor arguments. Don't emit add/remove/raise on events. Specify AttributeTargets.All on classes with AttributeUsage attribute. Force auto-properties to have get accessors. + -k, --must-compile Compilation tidying: try really hard to make code that compiles. Suppress generation of code for items with CompilerGenerated attribute. Comment out attributes without parameterless constructors or all-optional constructor arguments. Don't emit add/remove/raise on events. Specify AttributeTargets.All on classes with AttributeUsage attribute. Force auto-properties to have get accessors. Force regular properties to have bodies. ``` Defaults if not specified: