Output char field default values with printable syntax

This commit is contained in:
Katy Coe
2017-11-10 14:23:26 +01:00
parent 0a0876c337
commit 5e03e70abe

View File

@@ -17,7 +17,21 @@ namespace Il2CppInspector.Reflection {
public bool HasDefaultValue { get; }
public object DefaultValue { get; }
public string DefaultValueString => !HasDefaultValue ? "" : (DefaultValue is string? $"\"{DefaultValue}\"" : (DefaultValue?.ToString() ?? "null"));
public string DefaultValueString {
get {
if (!HasDefaultValue)
return "";
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}'";
}
}
// Information/flags about the field
public FieldAttributes Attributes { get; }