Skip to content

Commit

Permalink
Fix enum serialization (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
taks committed Jun 30, 2023
1 parent a4faf8c commit 9c71992
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tomlyn/Model/Accessors/ReflectionObjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ReflectionObjectInfo(ReflectionObjectKind kind, Type genericArgument1, Ty

public static ReflectionObjectInfo Get(Type type)
{
if (type == typeof(string) || type.IsPrimitive || type == typeof(TomlDateTime) || type == typeof(DateTime) || type == typeof(DateTimeOffset)
if (type == typeof(string) || type.IsPrimitive || type == typeof(TomlDateTime) || type == typeof(DateTime) || type == typeof(DateTimeOffset) || type.IsEnum
#if NET6_0_OR_GREATER
|| type == typeof(DateOnly) || type == typeof(TimeOnly)
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/Tomlyn/Model/ModelToTomlTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ private void WritePrimitive(object primitive, TomlPropertyDisplayKind displayKin
{
_writer.Write(TomlFormatHelper.ToString(dateTimeOffset, displayKind));
}
else if (primitive is Enum enumValue)
{
_writer.Write(TomlFormatHelper.ToString(enumValue.ToString(), displayKind));
}
#if NET6_0_OR_GREATER
else if (primitive is DateOnly dateOnly)
{
Expand Down

0 comments on commit 9c71992

Please sign in to comment.