fix(audit): ScadaBridge C3 review — safe enum-parse (fallback) in SqliteAuditWriter.MapRow + AuditEventDtoMapper.FromDto (Task 2.5)
This commit is contained in:
@@ -173,7 +173,13 @@ public static class AuditRowProjection
|
||||
return evt with { DetailsJson = AuditDetailsCodec.Serialize(d) };
|
||||
}
|
||||
|
||||
private static TEnum ParseEnum<TEnum>(string? value, TEnum fallback) where TEnum : struct, Enum
|
||||
/// <summary>
|
||||
/// Case-sensitive <see cref="Enum.TryParse{TEnum}"/> with a caller-supplied fallback.
|
||||
/// Returns <paramref name="fallback"/> when <paramref name="value"/> is null, empty,
|
||||
/// or does not match any declared member name — so callers never throw on an
|
||||
/// unknown/renamed enum string (legacy or corrupt rows degrade gracefully).
|
||||
/// </summary>
|
||||
public static TEnum ParseEnum<TEnum>(string? value, TEnum fallback) where TEnum : struct, Enum
|
||||
=> !string.IsNullOrEmpty(value) && Enum.TryParse<TEnum>(value, ignoreCase: false, out var parsed)
|
||||
? parsed
|
||||
: fallback;
|
||||
|
||||
Reference in New Issue
Block a user