Browse Source

Merge pull request #376 from ionite34/enum-fixes

pull/298/head
Ionite 12 months ago committed by GitHub
parent
commit
1147e0d950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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