fix(uns): omit blank optional keys from TagConfig + add omission tests; drop unused ParseInt (T4-T8 review)

This commit is contained in:
Joseph Doherty
2026-06-09 09:49:33 -04:00
parent 75021fa2c9
commit c0afecda50
10 changed files with 87 additions and 11 deletions
@@ -33,7 +33,10 @@ public static class TagConfigJson
public static TEnum GetEnum<TEnum>(JsonObject o, string name, TEnum fallback) where TEnum : struct, Enum
=> GetString(o, name) is { } s && Enum.TryParse<TEnum>(s, ignoreCase: true, out var v) ? v : fallback;
/// <summary>Sets a string/number/enum-name value (enums via ToString()). Null removes the key.</summary>
/// <summary>Sets a string/number/enum-name value (enums via ToString()). A null value REMOVES the key, so it is omitted from the serialised JSON.</summary>
public static void Set(JsonObject o, string name, object? value)
=> o[name] = value is null ? null : JsonValue.Create(value is Enum e ? e.ToString() : value);
{
if (value is null) { o.Remove(name); return; }
o[name] = JsonValue.Create(value is Enum e ? e.ToString() : value);
}
}