From 5e03e70abe3aee3208778df6c99c54d6abf99c7c Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Fri, 10 Nov 2017 14:23:26 +0100 Subject: [PATCH] Output char field default values with printable syntax --- Il2CppInspector/Reflection/FieldInfo.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Il2CppInspector/Reflection/FieldInfo.cs b/Il2CppInspector/Reflection/FieldInfo.cs index 46e312a..7d9f9f2 100644 --- a/Il2CppInspector/Reflection/FieldInfo.cs +++ b/Il2CppInspector/Reflection/FieldInfo.cs @@ -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; }