Skip to content

Commit f55286d

Browse files
author
Oren (electricessence)
committed
Reformat and contract improvments.
1 parent 5f1ce2b commit f55286d

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

CsvReader.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Open.Disposable;
22
using System;
33
using System.Collections.Generic;
4+
using System.Diagnostics.Contracts;
45
using System.IO;
5-
using System.Text;
66

77
namespace Open.Text.CSV
88
{
@@ -38,7 +38,8 @@ public string[][] ReadRows()
3838
public static bool TryGetRow(StreamReader source, out string[] row, ref int maxColumns)
3939
{
4040
if (source == null)
41-
throw new ArgumentNullException("source");
41+
throw new ArgumentNullException(nameof(source));
42+
Contract.EndContractBlock();
4243

4344
if (!source.EndOfStream)
4445
{
@@ -59,22 +60,24 @@ public static string[] GetRow(StreamReader source, ref int maxColumns)
5960
public static string[][] GetRows(StreamReader source, out int maxColumns)
6061
{
6162
if (source == null)
62-
throw new ArgumentNullException("source");
63+
throw new ArgumentNullException(nameof(source));
64+
Contract.EndContractBlock();
6365

6466
maxColumns = 0;
6567
var lines = new List<string[]>();
6668
while (TryGetRow(source, out string[] row, ref maxColumns))
67-
lines.Add(row);
69+
lines.Add(row);
6870

6971
return lines.ToArray();
7072
}
7173

7274
public static string[][] GetRowsFromFile(string filepath, out int maxColumns)
7375
{
7476
if (filepath == null)
75-
throw new ArgumentNullException("filepath");
77+
throw new ArgumentNullException(nameof(filepath));
7678
if (String.IsNullOrWhiteSpace(filepath))
77-
throw new ArgumentException("Cannot be empty or only whitespace.", "filepath");
79+
throw new ArgumentException("Cannot be empty or only whitespace.", nameof(filepath));
80+
Contract.EndContractBlock();
7881

7982
if (File.Exists(filepath))
8083
using (var s = new StreamReader((new FileInfo(filepath)).OpenRead()))

CsvRow.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.Contracts;
34
using System.Linq;
4-
using System.Text;
55

66
namespace Open.Text.CSV
77
{
88
public class CsvRow
99
{
1010
public CsvRow(string[] headerRow)
1111
{
12-
_headerRow = headerRow ?? throw new ArgumentNullException("headerRow");
12+
_headerRow = headerRow ?? throw new ArgumentNullException(nameof(headerRow));
1313
}
1414

1515
string[] _headerRow;
@@ -18,10 +18,12 @@ public CsvRow(string[] headerRow)
1818

1919
public string[] GetRow(IDictionary<string, object> values)
2020
{
21-
if(values==null) throw new ArgumentNullException("values");
21+
if (values == null) throw new ArgumentNullException(nameof(values));
22+
Contract.EndContractBlock();
23+
2224
return _headerRow
2325
.Select(key => values.TryGetValue(key, out object value) ? CsvUtility.ExportValue(value) : null)
2426
.ToArray();
2527
}
26-
}
28+
}
2729
}

CsvWriter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Open.Disposable;
22
using System;
33
using System.Collections.Generic;
4+
using System.Diagnostics.Contracts;
45
using System.IO;
56
using System.Text;
67

@@ -37,7 +38,8 @@ public static void WriteValue(TextWriter writer, object value = null, bool force
3738

3839
public static void WriteRow(TextWriter writer, object[] row, bool forceQuotes = false)
3940
{
40-
if (row == null) throw new ArgumentNullException("row");
41+
if (row == null) throw new ArgumentNullException(nameof(row));
42+
Contract.EndContractBlock();
4143

4244
foreach (var o in row)
4345
WriteValue(writer, o, forceQuotes);
@@ -47,7 +49,8 @@ public static void WriteRow(TextWriter writer, object[] row, bool forceQuotes =
4749

4850
public static void WriteRows(TextWriter writer, object[][] rows, bool forceQuotes = false)
4951
{
50-
if (rows == null) throw new ArgumentNullException("rows");
52+
if (rows == null) throw new ArgumentNullException(nameof(rows));
53+
Contract.EndContractBlock();
5154

5255
foreach (var row in rows)
5356
WriteRow(writer, row, forceQuotes);

ExcelCsvExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void WriteCsvExcelValue(this TextWriter writer, string value)
1212

1313
public static void WriteCsvExcelHyperlink(this TextWriter writer, Uri link, string text = null)
1414
{
15-
if (link == null) throw new ArgumentNullException("link");
15+
if (link == null) throw new ArgumentNullException(nameof(link));
1616

1717
writer.WriteCsvExcelHyperlink(link.ToString(), text);
1818
}
@@ -29,7 +29,7 @@ public static void WriteExcelValue(this CsvWriter writer, string value)
2929

3030
public static void WriteExcelHyperlink(this CsvWriter writer, Uri link, string text = null)
3131
{
32-
if (link == null) throw new ArgumentNullException("link");
32+
if (link == null) throw new ArgumentNullException(nameof(link));
3333

3434
WriteExcelHyperlink(writer, link.ToString(), text);
3535
}

0 commit comments

Comments
 (0)