Output: Prepend fields, events, properties and parameter names using reserved C# keywords with @

This commit is contained in:
Katy Coe
2019-12-12 10:18:55 +01:00
parent f10d52bdd2
commit f60047a55a
6 changed files with 53 additions and 5 deletions

View File

@@ -40,6 +40,7 @@ namespace Il2CppInspector.Reflection
// Name of parameter
public string Name { get; }
public string CSharpSafeName => Constants.Keywords.Contains(Name) ? "@" + Name : Name;
// Type of this parameter
private readonly int paramTypeUsage;
@@ -106,7 +107,7 @@ namespace Il2CppInspector.Reflection
public string GetParameterString(Scope usingScope, bool emitPointer = false, bool compileAttributes = false) => IsRetval? null :
(Position == 0 && DeclaringMethod.GetCustomAttributes("System.Runtime.CompilerServices.ExtensionAttribute").Any()? "this ":"")
+ $"{CustomAttributes.ToString(usingScope, inline: true, emitPointer: emitPointer, mustCompile: compileAttributes).Replace("[ParamArray]", "params")}"
+ $"{getCSharpSignatureString(usingScope)} {Name}"
+ $"{getCSharpSignatureString(usingScope)} {CSharpSafeName}"
+ (IsOptional? " = " + DefaultValue.ToCSharpValue(ParameterType, usingScope)
+ (emitPointer && !(DefaultValue is null)? $" /* Metadata: 0x{(uint) DefaultValueMetadataAddress:X8} */" : "") : "");