1- using Open . Disposable ;
2- using System ;
1+ using System ;
32using System . Collections . Generic ;
43using System . Diagnostics . Contracts ;
54using System . IO ;
65
76namespace 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
0 commit comments