Skip to content

Commit cb76e60

Browse files
author
Oren (electricessence)
committed
Resharper inspection fixes.
1 parent f55286d commit cb76e60

5 files changed

Lines changed: 23 additions & 17 deletions

File tree

CsvReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public string[] ReadRow()
3030

3131
public string[][] ReadRows()
3232
{
33-
var rows = GetRows(_source, out int maxColumns);
33+
var rows = GetRows(_source, out var maxColumns);
3434
if (maxColumns > _maxColumns) _maxColumns = maxColumns;
3535
return rows;
3636
}
@@ -53,7 +53,7 @@ public static bool TryGetRow(StreamReader source, out string[] row, ref int maxC
5353

5454
public static string[] GetRow(StreamReader source, ref int maxColumns)
5555
{
56-
TryGetRow(source, out string[] row, ref maxColumns);
56+
TryGetRow(source, out var row, ref maxColumns);
5757
return row;
5858
}
5959

@@ -65,7 +65,7 @@ public static string[][] GetRows(StreamReader source, out int maxColumns)
6565

6666
maxColumns = 0;
6767
var lines = new List<string[]>();
68-
while (TryGetRow(source, out string[] row, ref maxColumns))
68+
while (TryGetRow(source, out var row, ref maxColumns))
6969
lines.Add(row);
7070

7171
return lines.ToArray();
@@ -75,7 +75,7 @@ public static string[][] GetRowsFromFile(string filepath, out int maxColumns)
7575
{
7676
if (filepath == null)
7777
throw new ArgumentNullException(nameof(filepath));
78-
if (String.IsNullOrWhiteSpace(filepath))
78+
if (string.IsNullOrWhiteSpace(filepath))
7979
throw new ArgumentException("Cannot be empty or only whitespace.", nameof(filepath));
8080
Contract.EndContractBlock();
8181

CsvRow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public string[] GetRow(IDictionary<string, object> values)
2222
Contract.EndContractBlock();
2323

2424
return _headerRow
25-
.Select(key => values.TryGetValue(key, out object value) ? CsvUtility.ExportValue(value) : null)
25+
.Select(key => values.TryGetValue(key, out var value) ? CsvUtility.ExportValue(value) : null)
2626
.ToArray();
2727
}
2828
}

CsvUtility.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
53
using System.Text.RegularExpressions;
64

75
namespace Open.Text.CSV
@@ -18,12 +16,12 @@ public static string[] GetLine(string line, ref int maxColumns)
1816
return StringArrayEmpty;
1917

2018
var mc = LinePattern.Matches(line);
21-
int c = mc.Count;
19+
var c = mc.Count;
2220
if (c > maxColumns)
2321
maxColumns = c;
2422

2523
var result = new string[c];
26-
for (int i = 0; i < c; i++)
24+
for (var i = 0; i < c; i++)
2725
result[i] = mc[i].Groups[1].Value.Trim('"');
2826

2927
return result;
@@ -32,18 +30,18 @@ public static string[] GetLine(string line, ref int maxColumns)
3230
public static string[][] GetArray(string csv, out int maxColumns)
3331
{
3432
maxColumns = 0;
35-
string[] lines = csv == null ? new string[0] : csv.Split('\n');
33+
var lines = csv == null ? new string[0] : csv.Split('\n');
3634

3735
var result = new List<string[]>(lines.Length);
38-
foreach (string line in lines)
36+
foreach (var line in lines)
3937
result.Add(GetLine(line, ref maxColumns));
4038

4139
return result.ToArray();
4240
}
4341

4442
public static string[][] GetArray(string csv)
4543
{
46-
return GetArray(csv, out int maxColumns);
44+
return GetArray(csv, out var maxColumns);
4745
}
4846

4947

@@ -53,25 +51,25 @@ public static string[][] GetArray(string csv)
5351
public static string WrapQuotes(string value)
5452
{
5553
if (value == null)
56-
return String.Empty;
54+
return string.Empty;
5755

5856
return '"' + value.Replace("\"", "\"\"") + '"';
5957
}
6058

6159
public static string FormatValue(string value, bool forceQuotes = false)
6260
{
6361
if (value == null)
64-
return String.Empty;
62+
return string.Empty;
6563

66-
if (!String.IsNullOrEmpty(value) && forceQuotes || QUOTESNEEDED.IsMatch(value))
64+
if (!string.IsNullOrEmpty(value) && forceQuotes || QUOTESNEEDED.IsMatch(value))
6765
return WrapQuotes(value);
6866

6967
return value;
7068
}
7169

7270
public static string ExportValue(object value, bool forceQuotes = false)
7371
{
74-
string result = String.Empty;
72+
var result = string.Empty;
7573
if (value != null)// && value != DBNull.Value)
7674
{
7775
if (value is DateTime datetime)

ExcelCsvExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static void WriteCsvExcelHyperlink(this TextWriter writer, Uri link, stri
1919

2020
public static void WriteCsvExcelHyperlink(this TextWriter writer, string link, string text = null)
2121
{
22-
WriteCsvExcelValue(writer, "=HYPERLINK(" + CsvUtility.WrapQuotes(link) + (text == null ? String.Empty : ("," + CsvUtility.WrapQuotes(text))) + ")");
22+
WriteCsvExcelValue(writer, "=HYPERLINK(" + CsvUtility.WrapQuotes(link) + (text == null ? string.Empty : ("," + CsvUtility.WrapQuotes(text))) + ")");
2323
}
2424

2525
public static void WriteExcelValue(this CsvWriter writer, string value)

Open.Text.CSV.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ Part of the "Open" set of libraries.</Description>
2222
<PackageReleaseNotes>Updated to .NET Standard for compatability.</PackageReleaseNotes>
2323
</PropertyGroup>
2424

25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
26+
<LangVersion>latest</LangVersion>
27+
</PropertyGroup>
28+
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
30+
<LangVersion>latest</LangVersion>
31+
</PropertyGroup>
32+
2533
<ItemGroup>
2634
<Compile Remove="CsvData.cs" />
2735
<Compile Remove="Web.cs" />

0 commit comments

Comments
 (0)