Output: Move getParametersString into MethodBase/ParameterInfo

This commit is contained in:
Katy Coe
2019-10-31 23:23:52 +01:00
parent 3560661f9c
commit dbc3ef40b0
3 changed files with 11 additions and 20 deletions

View File

@@ -224,7 +224,7 @@ namespace Il2CppInspector
foreach (var method in type.DeclaredConstructors) {
writer.Write($"{prefix}\t{method.GetModifierString()}{method.DeclaringType.Name}(");
writer.Write(getParametersString(method.DeclaredParameters));
writer.Write(method.GetParametersString());
writer.Write(");" + (method.VirtualAddress != 0 ? $" // {formatAddress(method.VirtualAddress)}" : "") + "\n");
}
if (type.DeclaredConstructors.Any())
@@ -241,28 +241,10 @@ namespace Il2CppInspector
writer.Write($"{method.ReturnType.CSharpName} {method.CSharpName}");
else
writer.Write($"{method.CSharpName}{method.ReturnType.CSharpName}");
writer.Write("(" + getParametersString(method.DeclaredParameters));
writer.Write("(" + method.GetParametersString());
writer.Write(");" + (method.VirtualAddress != 0 ? $" // {formatAddress(method.VirtualAddress)}" : "") + "\n");
}
writer.Write(prefix + "}\n");
}
// TODO: Move this info ParameterInfo
private string getParametersString(List<ParameterInfo> @params) {
StringBuilder sb = new StringBuilder();
bool first = true;
foreach (var param in @params) {
if (!first)
sb.Append(", ");
first = false;
if (param.IsOptional)
sb.Append("optional ");
if (param.IsOut)
sb.Append("out ");
sb.Append($"{param.ParameterType.CSharpName} {param.Name}");
}
return sb.ToString();
}
}
}

View File

@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -137,6 +138,10 @@ namespace Il2CppInspector.Reflection
return modifiers.ToString();
}
// Get C# syntax-friendly list of parameters
public string GetParametersString() =>
string.Join(", ", DeclaredParameters.Select(p => $"{p.GetModifierString()}{p.ParameterType.CSharpName} {p.Name}"));
// List of operator overload metadata names
// https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/operator-overloads
public static Dictionary<string, string> OperatorMethodNames = new Dictionary<string, string> {

View File

@@ -69,5 +69,9 @@ namespace Il2CppInspector.Reflection
// TODO: DefaultValue/HasDefaultValue
}
public string GetModifierString() =>
(IsOptional? "optional " : "") +
(IsOut? "out " : "");
}
}