Refactor some string output helper functions into extension methods

This commit is contained in:
Katy Coe
2019-11-05 19:34:12 +01:00
parent 9d4d8da42b
commit 067cea9e5f
5 changed files with 51 additions and 44 deletions

View File

@@ -21,22 +21,7 @@ namespace Il2CppInspector.Reflection {
public bool HasDefaultValue { get; }
public object DefaultValue { get; }
public string DefaultValueString {
get {
if (!HasDefaultValue)
return "";
if (DefaultValue is bool)
return (bool) DefaultValue ? "true" : "false";
if (DefaultValue is string)
return $"\"{DefaultValue}\"";
if (!(DefaultValue is char))
return (DefaultValue?.ToString() ?? "null");
var cValue = (int) (char) DefaultValue;
if (cValue < 32 || cValue > 126)
return $"'\\x{cValue:x4}'";
return $"'{DefaultValue}'";
}
}
public string DefaultValueString => HasDefaultValue ? DefaultValue.ToCSharpValue() : "";
// Information/flags about the field
public FieldAttributes Attributes { get; }