Skip to content

Commit

Permalink
Fix usage of linq for older versions of dotnet
Browse files Browse the repository at this point in the history
  • Loading branch information
tspence committed Aug 5, 2024
1 parent 002e990 commit 461562c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/CSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 461562c

Please sign in to comment.