From 461562c49ea6c18733ae978f3a48ee53571ce67d Mon Sep 17 00:00:00 2001 From: Ted Spence Date: Mon, 5 Aug 2024 15:20:54 -0700 Subject: [PATCH] Fix usage of linq for older versions of dotnet --- src/CSV.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/CSV.cs b/src/CSV.cs index 755ce11..8b014f7 100644 --- a/src/CSV.cs +++ b/src/CSV.cs @@ -7,7 +7,6 @@ using System.Collections; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; #if HAS_ASYNC using System.Threading.Tasks; @@ -360,11 +359,24 @@ internal static string ItemsToCsv(IEnumerable items, CSVSettings settings, char[ // Special cases for other types of serialization string s; var itemType = item.GetType(); + var interfaces = itemType.GetInterfaces(); + bool isEnumerable = false; + if (itemType != typeof(string)) + { + foreach (var itemInterface in interfaces) + { + if (itemInterface == typeof(IEnumerable)) + { + isEnumerable = true; + } + } + } + if (item is DateTime) { s = ((DateTime)item).ToString(settings.DateTimeFormat); } - else if (itemType != typeof(string) && itemType.GetInterfaces().Contains(typeof(IEnumerable))) + else if (isEnumerable) { IEnumerable enumerable = item as IEnumerable; s = string.Empty;