Browse Source

Add case insensitive enum match fallback

pull/298/head
Ionite 12 months ago
parent
commit
ed3b115df2
No known key found for this signature in database
  1. 12
      StabilityMatrix.Core/Converters/Json/DefaultUnknownEnumConverter.cs

12
StabilityMatrix.Core/Converters/Json/DefaultUnknownEnumConverter.cs

@ -81,11 +81,23 @@ public class DefaultUnknownEnumConverter<
if (reader.GetString() is { } readerString)
{
// First try get exact match
if (EnumMemberValues.TryGetValue(readerString, out var enumMemberValue))
{
return enumMemberValue;
}
// Otherwise try get case-insensitive match
if (
EnumMemberValues.Keys.FirstOrDefault(
key => key.Equals(readerString, StringComparison.OrdinalIgnoreCase)
) is
{ } enumMemberName
)
{
return EnumMemberValues[enumMemberName];
}
Debug.WriteLine($"Unknown enum member value for {typeToConvert}: {readerString}");
}

Loading…
Cancel
Save