Output: Don't initialize statics or consts to default in struct constructors (CS0131)

This commit is contained in:
Katy Coe
2020-02-05 10:29:08 +01:00
parent fdfef84cce
commit 3981557601

View File

@@ -491,8 +491,9 @@ namespace Il2CppInspector
// Struct construvctors must initialize all fields in the struct // Struct construvctors must initialize all fields in the struct
if (fields.Any()) { if (fields.Any()) {
var paramNames = method.DeclaredParameters.Select(p => p.Name); var paramNames = method.DeclaredParameters.Select(p => p.Name);
sb.Append(" {\n" + string.Join("\n", sb.Append(" {\n" + string.Join("\n", fields
fields.Select(f => $"{prefix}\t\t{(paramNames.Contains(f.Name) ? "this." : "")}{f.Name} = default;")) .Where(f => !f.IsStatic && !f.IsLiteral)
.Select(f => $"{prefix}\t\t{(paramNames.Contains(f.Name) ? "this." : "")}{f.Name} = default;"))
+ $"\n{prefix}\t}}"); + $"\n{prefix}\t}}");
} else } else
sb.Append(" {}"); sb.Append(" {}");