Output: Generate dummy constructors when using MustCompile (CS1729, CS7036)
This commit is contained in:
@@ -468,6 +468,12 @@ namespace Il2CppInspector
|
|||||||
var fields = type.DeclaredFields.Where(f => !f.GetCustomAttributes(CGAttribute).Any());
|
var fields = type.DeclaredFields.Where(f => !f.GetCustomAttributes(CGAttribute).Any());
|
||||||
|
|
||||||
sb.Clear();
|
sb.Clear();
|
||||||
|
|
||||||
|
// Crete a parameterless constructor for every relevant type when making code that compiles to mitigate CS1729 and CS7036
|
||||||
|
if (MustCompile && !type.IsInterface && !(type.IsAbstract && type.IsSealed) && !type.IsValueType
|
||||||
|
&& type.DeclaredConstructors.All(c => c.IsStatic || c.DeclaredParameters.Any()))
|
||||||
|
sb.Append($"{prefix}\t{(type.IsAbstract? "protected" : "public")} {type.UnmangledBaseName}() {{}} // Dummy constructor\n");
|
||||||
|
|
||||||
foreach (var method in type.DeclaredConstructors) {
|
foreach (var method in type.DeclaredConstructors) {
|
||||||
// Attributes
|
// Attributes
|
||||||
sb.Append(method.CustomAttributes.OrderBy(a => a.AttributeType.Name)
|
sb.Append(method.CustomAttributes.OrderBy(a => a.AttributeType.Name)
|
||||||
@@ -649,7 +655,7 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// Ref return type requires us to invent a field
|
// Ref return type requires us to invent a field
|
||||||
if (MustCompile && method.ReturnType.IsByRef)
|
if (MustCompile && method.ReturnType.IsByRef)
|
||||||
writer.Append($"{prefix}\tprivate {method.ReturnType.GetScopedCSharpName(scope)} _refReturnTypeFor{method.CSharpName};\n");
|
writer.Append($"{prefix}\tprivate {method.ReturnType.GetScopedCSharpName(scope)} _refReturnTypeFor{method.CSharpName}; // Dummy field\n");
|
||||||
|
|
||||||
return writer.ToString();
|
return writer.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,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")]
|
[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; }
|
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. Force regular properties to have bodies. Suppress global::Locale classes.")]
|
[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. Suppress global::Locale classes. Generate dummy parameterless base constructors and ref return fields.")]
|
||||||
public bool MustCompile { get; set; }
|
public bool MustCompile { get; set; }
|
||||||
|
|
||||||
[Option("separate-attributes", Required = false, HelpText = "Place assembly-level attributes in their own AssemblyInfo.cs files. Only used when layout is per-assembly or tree")]
|
[Option("separate-attributes", Required = false, HelpText = "Place assembly-level attributes in their own AssemblyInfo.cs files. Only used when layout is per-assembly or tree")]
|
||||||
|
|||||||
Reference in New Issue
Block a user