Skip to content

Commit

Permalink
Fix PrimitiveConverterProvider (#131)
Browse files Browse the repository at this point in the history
- when an enum underlying type is not an Int32
  • Loading branch information
mcatanzariti authored Apr 8, 2024
1 parent 2661276 commit c12a6c3
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public class PrimitiveConverterProvider : CborConverterProviderBase
{
public override ICborConverter? GetConverter(Type type, CborOptions options)
{
if (type.IsEnum)
{
return CreateGenericConverter(options, typeof(EnumConverter<>), type);
}

switch (Type.GetTypeCode(type))
{
case TypeCode.Boolean:
Expand All @@ -24,15 +29,7 @@ public class PrimitiveConverterProvider : CborConverterProviderBase
case TypeCode.Int16:
return new Int16Converter();
case TypeCode.Int32:
if (type.IsEnum)
{
return CreateGenericConverter(options, typeof(EnumConverter<>), type);
}
else if (type == typeof(int))
{
return new Int32Converter();
}
break;
return new Int32Converter();
case TypeCode.Int64:
return new Int64Converter();
case TypeCode.SByte:
Expand Down

0 comments on commit c12a6c3

Please sign in to comment.