1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
// Copyright 2009-2022 Josh Close
// This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0.
// https://github.com/JoshClose/CsvHelper
using System;
using CsvHelper.Configuration;
using CsvHelper.TypeConversion;
namespace CsvHelper
{
/// <summary>
/// Defines methods used to write a CSV row.
/// </summary>
public interface IWriterRow
{
/// <summary>
/// The header record.
/// </summary>
string[] HeaderRecord { get; }
/// <summary>
/// The current row.
/// </summary>
int Row { get; }
/// <summary>
/// The current field index.
/// </summary>
int Index { get; }
/// <summary>
/// Gets the writing context.
/// </summary>
CsvContext Context { get; }
/// <summary>
/// Gets or sets the configuration.
/// </summary>
IWriterConfiguration Configuration { get; }
/// <summary>
/// Writes a field that has already been converted to a
/// <see cref="string"/> from an <see cref="ITypeConverter"/>.
/// If the field is null, it won't get written. A type converter
/// will always return a string, even if field is null. If the
/// converter returns a null, it means that the converter has already
/// written data, and the returned value should not be written.
/// </summary>
/// <param name="field">The converted field to write.</param>
/// <param name="fieldType">The type of the field before it was converted into a string.</param>
void WriteConvertedField(string field, Type fieldType);
/// <summary>
/// Writes the field to the CSV file. The field
/// may get quotes added to it.
/// When all fields are written for a record,
/// <see cref="IWriter.NextRecord()" /> must be called
/// to complete writing of the current record.
/// </summary>
/// <param name="field">The field to write.</param>
void WriteField(string field);
/// <summary>
/// Writes the field to the CSV file. This will
/// ignore any need to quote and ignore
/// <see cref="CsvHelper.Configuration.CsvConfiguration.ShouldQuote"/>
/// and just quote based on the shouldQuote
/// parameter.
/// When all fields are written for a record,
/// <see cref="IWriter.NextRecord()" /> must be called
/// to complete writing of the current record.
/// </summary>
/// <param name="field">The field to write.</param>
/// <param name="shouldQuote">True to quote the field, otherwise false.</param>
void WriteField(string field, bool shouldQuote);
/// <summary>
/// Writes the field to the CSV file.
/// When all fields are written for a record,
/// <see cref="IWriter.NextRecord()" /> must be called
/// to complete writing of the current record.
/// </summary>
/// <typeparam name="T">The type of the field.</typeparam>
/// <param name="field">The field to write.</param>
void WriteField<T>(T field);
/// <summary>
/// Writes the field to the CSV file.
/// When all fields are written for a record,
/// <see cref="IWriter.NextRecord" /> must be called
/// to complete writing of the current record.
/// </summary>
/// <typeparam name="T">The type of the field.</typeparam>
/// <param name="field">The field to write.</param>
/// <param name="converter">The converter used to convert the field into a string.</param>
void WriteField<T>(T field, ITypeConverter converter);
/// <summary>
/// Writes the field to the CSV file
/// using the given <see cref="ITypeConverter"/>.
/// When all fields are written for a record,
/// <see cref="IWriter.NextRecord()" /> must be called
/// to complete writing of the current record.
/// </summary>
/// <typeparam name="T">The type of the field.</typeparam>
/// <typeparam name="TConverter">The type of the converter.</typeparam>
/// <param name="field">The field to write.</param>
void WriteField<T, TConverter>(T field);
/// <summary>
/// Writes a comment.
/// </summary>
/// <param name="comment">The comment to write.</param>
void WriteComment(string comment);
/// <summary>
/// Writes the header record from the given members.
/// </summary>
/// <typeparam name="T">The type of the record.</typeparam>
void WriteHeader<T>();
/// <summary>
/// Writes the header record from the given members.
/// </summary>
/// <param name="type">The type of the record.</param>
void WriteHeader(Type type);
/// <summary>
/// Writes the record to the CSV file.
/// </summary>
/// <typeparam name="T">The type of the record.</typeparam>
/// <param name="record">The record to write.</param>
void WriteRecord<T>(T record);
}
}
|