Skip to content

Commit 0a3f62e

Browse files
author
Oren (electricessence)
committed
Non-crucial inspection fixes.
1 parent cb76e60 commit 0a3f62e

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

CsvRow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public CsvRow(string[] headerRow)
1212
_headerRow = headerRow ?? throw new ArgumentNullException(nameof(headerRow));
1313
}
1414

15-
string[] _headerRow;
15+
readonly string[] _headerRow;
1616

1717
public string[] HeaderRow => _headerRow.ToArray();
1818

CsvUtility.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Text.RegularExpressions;
45

56
namespace Open.Text.CSV
67
{
7-
public static partial class CsvUtility
8+
public static class CsvUtility
89
{
910
public const string LINE_PATTERN = "((?:\")([^\"]+)(?:\")|([^,\"]+))(?:\\s*)(?:,|$)";
1011
public static readonly Regex LinePattern = new Regex(LINE_PATTERN);
@@ -33,6 +34,7 @@ public static string[][] GetArray(string csv, out int maxColumns)
3334
var lines = csv == null ? new string[0] : csv.Split('\n');
3435

3536
var result = new List<string[]>(lines.Length);
37+
// ReSharper disable once LoopCanBeConvertedToQuery
3638
foreach (var line in lines)
3739
result.Add(GetLine(line, ref maxColumns));
3840

@@ -41,12 +43,12 @@ public static string[][] GetArray(string csv, out int maxColumns)
4143

4244
public static string[][] GetArray(string csv)
4345
{
44-
return GetArray(csv, out var maxColumns);
46+
return GetArray(csv, out _);
4547
}
4648

4749

4850
public const string NEWLINE = "\r\n";
49-
public readonly static Regex QUOTESNEEDED = new Regex("^\\s+|[,\n]|\\s+$");
51+
public static readonly Regex QUOTESNEEDED = new Regex("^\\s+|[,\n]|\\s+$");
5052

5153
public static string WrapQuotes(string value)
5254
{
@@ -70,17 +72,20 @@ public static string FormatValue(string value, bool forceQuotes = false)
7072
public static string ExportValue(object value, bool forceQuotes = false)
7173
{
7274
var result = string.Empty;
73-
if (value != null)// && value != DBNull.Value)
75+
switch (value)
7476
{
75-
if (value is DateTime datetime)
76-
{
77+
case null:
78+
return FormatValue(result, forceQuotes) + ",";
79+
case DateTime datetime:
7780
result = datetime.TimeOfDay == TimeSpan.Zero ?
7881
datetime.ToString("d") : // Use short date.
79-
datetime.ToString();
80-
}
81-
else
82+
datetime.ToString(CultureInfo.InvariantCulture);
83+
break;
84+
default:
8285
result = value.ToString();
86+
break;
8387
}
88+
8489
return FormatValue(result, forceQuotes) + ",";
8590
}
8691

CsvWriter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using Open.Disposable;
22
using System;
3-
using System.Collections.Generic;
43
using System.Diagnostics.Contracts;
54
using System.IO;
6-
using System.Text;
75

86
namespace Open.Text.CSV
97
{

Open.Text.CSV.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Part of the "Open" set of libraries.</Description>
4343
</ItemGroup>
4444

4545
<ItemGroup>
46-
<PackageReference Include="Open.Disposable" Version="1.1.0" />
46+
<PackageReference Include="Open.Disposable" Version="1.2.1" />
4747
<PackageReference Include="Open.Text" Version="1.1.0" />
4848
</ItemGroup>
4949

0 commit comments

Comments
 (0)