Skip to content

Commit 8bfc823

Browse files
author
Oren (electricessence)
committed
Cleanup to unhook Open.Disposable.
1 parent f8a18c4 commit 8bfc823

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

CsvReader.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using Open.Disposable;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Diagnostics.Contracts;
54
using System.IO;
65
using System.Threading.Tasks;
76

87
namespace Open.Text.CSV
98
{
10-
public class CsvReader : DisposableBase
9+
public class CsvReader : IDisposable
1110
{
1211
public CsvReader(StreamReader source)
1312
{
@@ -17,7 +16,7 @@ public CsvReader(StreamReader source)
1716
StreamReader _source;
1817

1918

20-
protected override void OnDispose(bool calledExplicitly)
19+
public void Dispose()
2120
{
2221
_source = null; // The intention here is if this object is disposed, then prevent further reading.
2322
}
@@ -96,7 +95,7 @@ public static IEnumerable<IEnumerable<string>> GetRowsFromFile(string filepath)
9695

9796
if (File.Exists(filepath))
9897
{
99-
using (var s = new StreamReader((new FileInfo(filepath)).OpenRead()))
98+
using (var s = new StreamReader(new FileInfo(filepath).OpenRead()))
10099
foreach (var line in GetRows(s))
101100
yield return line;
102101
}

CsvWriter.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
using Open.Disposable;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Diagnostics.Contracts;
54
using System.IO;
65

76
namespace Open.Text.CSV
87
{
9-
public class CsvWriter : DisposableBase
8+
public class CsvWriter : IDisposable
109
{
1110
internal TextWriter Target;
1211

1312
public CsvWriter(TextWriter target)
1413
{
15-
Target = target;
14+
Target = target ?? throw new ArgumentNullException(nameof(target));
1615
}
1716

18-
protected override void OnDispose(bool calledExplicitly)
17+
public void Dispose()
1918
{
2019
Target = null; // The intention here is if this object is disposed, then prevent further writing.
2120
}
2221

2322
public void WriteRow<T>(IEnumerable<T> row, bool forceQuotes = false)
2423
{
25-
WriteRow(Target, row, forceQuotes);
24+
WriteRow(Target ?? throw new ObjectDisposedException(GetType().ToString()), row, forceQuotes);
2625
}
2726

2827
public void WriteRows<T>(IEnumerable<IEnumerable<T>> rows, bool forceQuotes = false)
2928
{
30-
WriteRows(Target, rows, forceQuotes);
29+
WriteRows(Target ?? throw new ObjectDisposedException(GetType().ToString()), rows, forceQuotes);
3130
}
3231

3332
public static void WriteValue(TextWriter writer, object value = null, bool forceQuotes = false)
3433
{
34+
if (writer == null) throw new ArgumentNullException(nameof(writer));
35+
Contract.EndContractBlock();
36+
3537
writer.Write(CsvUtility.ExportValue(value, forceQuotes));
3638
}
3739

3840
public static void WriteRow<T>(TextWriter writer, IEnumerable<T> row, bool forceQuotes = false)
3941
{
42+
if (writer == null) throw new ArgumentNullException(nameof(writer));
4043
if (row == null) throw new ArgumentNullException(nameof(row));
4144
Contract.EndContractBlock();
4245

@@ -48,6 +51,7 @@ public static void WriteRow<T>(TextWriter writer, IEnumerable<T> row, bool force
4851

4952
public static void WriteRows<T>(TextWriter writer, IEnumerable<IEnumerable<T>> rows, bool forceQuotes = false)
5053
{
54+
if (writer == null) throw new ArgumentNullException(nameof(writer));
5155
if (rows == null) throw new ArgumentNullException(nameof(rows));
5256
Contract.EndContractBlock();
5357

Open.Text.CSV.csproj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Part of the "Open" set of libraries.</Description>
1616
<RepositoryUrl>https://github.com/electricessence/Open.Text.CSV/</RepositoryUrl>
1717
<RepositoryType>git</RepositoryType>
1818
<PackageTags>csv, csharp, dotnetcore, textwriter, streamreader</PackageTags>
19-
<Version>2.0.1</Version>
20-
<AssemblyVersion>2.0.1.0</AssemblyVersion>
21-
<FileVersion>2.0.1.0</FileVersion>
19+
<Version>2.1.0</Version>
20+
<AssemblyVersion>2.1.0.0</AssemblyVersion>
21+
<FileVersion>2.1.0.0</FileVersion>
2222
<PackageReleaseNotes></PackageReleaseNotes>
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2424
</PropertyGroup>
@@ -42,14 +42,13 @@ Part of the "Open" set of libraries.</Description>
4242
<None Remove="LICENSE" />
4343
<None Remove="README.md" />
4444
</ItemGroup>
45-
46-
<ItemGroup>
47-
<PackageReference Include="Open.Disposable" Version="2.0.1" />
48-
<PackageReference Include="Open.Text" Version="2.0.5" />
49-
</ItemGroup>
5045

5146
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
5247
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
5348
</ItemGroup>
49+
50+
<ItemGroup>
51+
<PackageReference Include="Open.Text" Version="2.0.5" />
52+
</ItemGroup>
5453

5554
</Project>

0 commit comments

Comments
 (0)