From c2a35fbad8704b1cfe28daad3a55da49c0afb5c1 Mon Sep 17 00:00:00 2001
From: Michiel van Oudheusden <mvanoudheusden@xpirit.com>
Date: Wed, 18 Sep 2024 13:58:36 +0200
Subject: [PATCH] Fix null instance

---
 src/OutputFormatters/CsvOutputFormatter.cs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/OutputFormatters/CsvOutputFormatter.cs b/src/OutputFormatters/CsvOutputFormatter.cs
index c4a257b..dec829c 100644
--- a/src/OutputFormatters/CsvOutputFormatter.cs
+++ b/src/OutputFormatters/CsvOutputFormatter.cs
@@ -182,7 +182,11 @@ public class CustomDoubleConverter : DoubleConverter
 {
     public override string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData)
     {
-        double number = (double)value;
-        return number.ToString("F8", CultureInfo.InvariantCulture);
+        return value switch
+        {
+            null => string.Empty,
+            double number => number.ToString("F8", CultureInfo.InvariantCulture),
+            _ => throw new InvalidOperationException("The value is not a double.")
+        };
     }
 }
\ No newline at end of file