Output: Give non-auto-properties accessor bodies (CS8080)
This commit is contained in:
@@ -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} {{ ");
|
||||
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
|
||||
@@ -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 =>
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user