fix(uns): omit blank optional keys from TagConfig + add omission tests; drop unused ParseInt (T4-T8 review)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user