Skip to content

Commit 4bba63c

Browse files
Fixed minor edge case bug in enum mapping
1 parent 26c9228 commit 4bba63c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/MiniExcel.OpenXml/OpenXmlWriter.DefaultOpenXml.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,16 @@ private Tuple<string, string, string> GetCellValue(int rowIndex, int cellIndex,
178178
#endif
179179
if (type.IsEnum)
180180
{
181-
var name = Enum.GetName(type, value) ?? "";
182-
var description = type.GetField(name)
183-
?.GetCustomAttribute<DescriptionAttribute>()
184-
?.Description ?? name;
181+
string? description = null;
182+
var name = Enum.GetName(type, value);
185183

184+
if (!string.IsNullOrEmpty(name))
185+
{
186+
var descAttr = type.GetField(name)?.GetCustomAttribute<DescriptionAttribute>();
187+
description = descAttr?.Description ?? name;
188+
}
189+
190+
description ??= value.ToString();
186191
return Tuple.Create("2", "str", description);
187192
}
188193

0 commit comments

Comments
 (0)