Output: Parameterized struct constructors must call parameterless constructor (CS0843)

This commit is contained in:
Katy Coe
2019-12-02 08:12:12 +01:00
parent ae782f4a3a
commit 231339add3

View File

@@ -336,16 +336,27 @@ namespace Il2CppInspector
sb.Append($"{prefix}\t{method.GetModifierString()}{method.DeclaringType.UnmangledBaseName}{method.GetTypeParametersString(scope)}"); sb.Append($"{prefix}\t{method.GetModifierString()}{method.DeclaringType.UnmangledBaseName}{method.GetTypeParametersString(scope)}");
sb.Append($"({method.GetParametersString(scope, !SuppressMetadata)})"); sb.Append($"({method.GetParametersString(scope, !SuppressMetadata)})");
// Class constructor
if (method.IsAbstract) if (method.IsAbstract)
sb.Append(";"); sb.Append(";");
else if (!type.IsValueType || !fields.Any()) else if (!type.IsValueType)
sb.Append(" {}"); sb.Append(" {}");
// Struct constructors must initialize all fields in the struct
// Struct constructor
else { else {
var paramNames = method.DeclaredParameters.Select(p => p.Name); // Parameterized struct constructors must call the parameterless constructor to create the object
sb.Append(" {\n" + string.Join("\n", // if the object has any auto-implemented properties
fields.Select(f => $"{prefix}\t\t{(paramNames.Contains(f.Name) ? "this." : "")}{f.Name} = default;")) if (type.DeclaredProperties.Any() && method.DeclaredParameters.Any())
+ $"\n{prefix}\t}}"); sb.Append(" : this()");
// Struct construvctors must initialize all fields in the struct
if (fields.Any()) {
var paramNames = method.DeclaredParameters.Select(p => p.Name);
sb.Append(" {\n" + string.Join("\n",
fields.Select(f => $"{prefix}\t\t{(paramNames.Contains(f.Name) ? "this." : "")}{f.Name} = default;"))
+ $"\n{prefix}\t}}");
} else
sb.Append(" {}");
} }
sb.Append((!SuppressMetadata && method.VirtualAddress != null ? $" // {method.VirtualAddress.ToAddressString()}" : "") + "\n"); sb.Append((!SuppressMetadata && method.VirtualAddress != null ? $" // {method.VirtualAddress.ToAddressString()}" : "") + "\n");