C#: Sanitize parameter names (#70)

This commit is contained in:
Katy Coe
2020-09-14 12:26:37 +02:00
parent 47cd6b928b
commit ff7110144a

View File

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