From 9c7199214392f6b7a84641b33a47de26073a16f7 Mon Sep 17 00:00:00 2001 From: taks <857tn859@gmail.com> Date: Fri, 30 Jun 2023 13:48:10 +0900 Subject: [PATCH] Fix enum serialization (#55) --- src/Tomlyn/Model/Accessors/ReflectionObjectInfo.cs | 2 +- src/Tomlyn/Model/ModelToTomlTransform.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Tomlyn/Model/Accessors/ReflectionObjectInfo.cs b/src/Tomlyn/Model/Accessors/ReflectionObjectInfo.cs index fa88392..79467bf 100644 --- a/src/Tomlyn/Model/Accessors/ReflectionObjectInfo.cs +++ b/src/Tomlyn/Model/Accessors/ReflectionObjectInfo.cs @@ -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 diff --git a/src/Tomlyn/Model/ModelToTomlTransform.cs b/src/Tomlyn/Model/ModelToTomlTransform.cs index 4d84af4..a139dda 100644 --- a/src/Tomlyn/Model/ModelToTomlTransform.cs +++ b/src/Tomlyn/Model/ModelToTomlTransform.cs @@ -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) {