• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 15646441728

14 Jun 2025 12:32AM UTC coverage: 54.81% (+0.1%) from 54.709%
15646441728

push

github

pwelter34
update documentation

1696 of 3584 branches covered (47.32%)

Branch coverage included in aggregate %.

4298 of 7352 relevant lines covered (58.46%)

233.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

24.49
/src/FluentCommand.SqlServer/Merge/DataReaderWrapper.cs
1
using System.Data;
2

3
namespace FluentCommand.Merge;
4

5
/// <summary>
6
/// Wraps an <see cref="IDataReader"/> and optionally applies a prefix to field names when accessing data.
7
/// </summary>
8
public class DataReaderWrapper : IDataReader
9
{
10
    private readonly IDataReader _dataReader;
11
    private readonly string _fieldPrefix;
12

13
    /// <summary>
14
    /// Initializes a new instance of the <see cref="DataReaderWrapper"/> class with the specified data reader.
15
    /// </summary>
16
    /// <param name="dataReader">The underlying <see cref="IDataReader"/> to wrap.</param>
17
    public DataReaderWrapper(IDataReader dataReader)
18
        : this(dataReader, null)
×
19
    {
20
    }
×
21

22
    /// <summary>
23
    /// Initializes a new instance of the <see cref="DataReaderWrapper"/> class with the specified data reader and field prefix.
24
    /// </summary>
25
    /// <param name="dataReader">The underlying <see cref="IDataReader"/> to wrap.</param>
26
    /// <param name="fieldPrefix">The prefix to apply to field names when accessing data, or <c>null</c> for no prefix.</param>
27
    public DataReaderWrapper(IDataReader dataReader, string fieldPrefix)
4✔
28
    {
29
        _dataReader = dataReader;
4✔
30
        _fieldPrefix = fieldPrefix;
4✔
31
    }
4✔
32

33
    /// <summary>
34
    /// Gets the name of the field at the specified index.
35
    /// </summary>
36
    /// <param name="i">The zero-based index of the field.</param>
37
    /// <returns>The name of the field, or an empty string if there is no value to return.</returns>
38
    public string GetName(int i) => _dataReader.GetName(i);
×
39

40
    /// <summary>
41
    /// Gets the data type information for the specified field.
42
    /// </summary>
43
    /// <param name="i">The zero-based index of the field.</param>
44
    /// <returns>The data type information for the specified field.</returns>
45
    public string GetDataTypeName(int i) => _dataReader.GetDataTypeName(i);
×
46

47
    /// <summary>
48
    /// Gets the <see cref="Type"/> information corresponding to the type of <see cref="object"/> that would be returned from <see cref="GetValue(int)"/>.
49
    /// </summary>
50
    /// <param name="i">The zero-based index of the field.</param>
51
    /// <returns>The <see cref="Type"/> of the field value.</returns>
52
    public Type GetFieldType(int i) => _dataReader.GetFieldType(i);
1,200✔
53

54
    /// <summary>
55
    /// Gets the value of the specified field.
56
    /// </summary>
57
    /// <param name="i">The zero-based index of the field.</param>
58
    /// <returns>The value of the field as an <see cref="object"/>.</returns>
59
    public object GetValue(int i) => _dataReader.GetValue(i);
800✔
60

61
    /// <summary>
62
    /// Populates an array of objects with the column values of the current record.
63
    /// </summary>
64
    /// <param name="values">An array of <see cref="object"/> to copy the attribute fields into.</param>
65
    /// <returns>The number of objects in the array.</returns>
66
    public int GetValues(object[] values) => _dataReader.GetValues(values);
×
67

68
    /// <summary>
69
    /// Gets the index of the field with the specified name, applying the field prefix if set.
70
    /// </summary>
71
    /// <param name="name">The name of the field to find.</param>
72
    /// <returns>The zero-based index of the named field.</returns>
73
    public int GetOrdinal(string name)
74
    {
75
        string prefixName = _fieldPrefix != null
3,600!
76
            ? _fieldPrefix + name
3,600✔
77
            : name;
3,600✔
78

79
        return _dataReader.GetOrdinal(prefixName);
3,600✔
80
    }
81

82
    /// <summary>
83
    /// Gets the value of the specified column as a <see cref="bool"/>.
84
    /// </summary>
85
    /// <param name="i">The zero-based column ordinal.</param>
86
    /// <returns>The value of the column as a <see cref="bool"/>.</returns>
87
    public bool GetBoolean(int i) => _dataReader.GetBoolean(i);
×
88

89
    /// <summary>
90
    /// Gets the 8-bit unsigned integer value of the specified column.
91
    /// </summary>
92
    /// <param name="i">The zero-based column ordinal.</param>
93
    /// <returns>The 8-bit unsigned integer value of the specified column.</returns>
94
    public byte GetByte(int i) => _dataReader.GetByte(i);
×
95

96
    /// <summary>
97
    /// Reads a stream of bytes from the specified column offset into the buffer as an array, starting at the given buffer offset.
98
    /// </summary>
99
    /// <param name="i">The zero-based column ordinal.</param>
100
    /// <param name="fieldOffset">The index within the field from which to start the read operation.</param>
101
    /// <param name="buffer">The buffer into which to read the stream of bytes.</param>
102
    /// <param name="bufferOffset">The index for buffer to start the read operation.</param>
103
    /// <param name="length">The number of bytes to read.</param>
104
    /// <returns>The actual number of bytes read.</returns>
105
    public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferOffset, int length) => _dataReader.GetBytes(i, fieldOffset, buffer, bufferOffset, length);
×
106

107
    /// <summary>
108
    /// Gets the character value of the specified column.
109
    /// </summary>
110
    /// <param name="i">The zero-based column ordinal.</param>
111
    /// <returns>The character value of the specified column.</returns>
112
    public char GetChar(int i) => _dataReader.GetChar(i);
×
113

114
    /// <summary>
115
    /// Reads a stream of characters from the specified column offset into the buffer as an array, starting at the given buffer offset.
116
    /// </summary>
117
    /// <param name="i">The zero-based column ordinal.</param>
118
    /// <param name="fieldOffset">The index within the row from which to start the read operation.</param>
119
    /// <param name="buffer">The buffer into which to read the stream of characters.</param>
120
    /// <param name="bufferOffset">The index for buffer to start the read operation.</param>
121
    /// <param name="length">The number of characters to read.</param>
122
    /// <returns>The actual number of characters read.</returns>
123
    public long GetChars(int i, long fieldOffset, char[] buffer, int bufferOffset, int length) => _dataReader.GetChars(i, fieldOffset, buffer, bufferOffset, length);
×
124

125
    /// <summary>
126
    /// Gets the <see cref="Guid"/> value of the specified field.
127
    /// </summary>
128
    /// <param name="i">The zero-based index of the field.</param>
129
    /// <returns>The <see cref="Guid"/> value of the specified field.</returns>
130
    public Guid GetGuid(int i) => _dataReader.GetGuid(i);
×
131

132
    /// <summary>
133
    /// Gets the 16-bit signed integer value of the specified field.
134
    /// </summary>
135
    /// <param name="i">The zero-based index of the field.</param>
136
    /// <returns>The 16-bit signed integer value of the specified field.</returns>
137
    public short GetInt16(int i) => _dataReader.GetInt16(i);
×
138

139
    /// <summary>
140
    /// Gets the 32-bit signed integer value of the specified field.
141
    /// </summary>
142
    /// <param name="i">The zero-based index of the field.</param>
143
    /// <returns>The 32-bit signed integer value of the specified field.</returns>
144
    public int GetInt32(int i) => _dataReader.GetInt32(i);
×
145

146
    /// <summary>
147
    /// Gets the 64-bit signed integer value of the specified field.
148
    /// </summary>
149
    /// <param name="i">The zero-based index of the field.</param>
150
    /// <returns>The 64-bit signed integer value of the specified field.</returns>
151
    public long GetInt64(int i) => _dataReader.GetInt64(i);
×
152

153
    /// <summary>
154
    /// Gets the single-precision floating point number of the specified field.
155
    /// </summary>
156
    /// <param name="i">The zero-based index of the field.</param>
157
    /// <returns>The single-precision floating point number of the specified field.</returns>
158
    public float GetFloat(int i) => _dataReader.GetFloat(i);
×
159

160
    /// <summary>
161
    /// Gets the double-precision floating point number of the specified field.
162
    /// </summary>
163
    /// <param name="i">The zero-based index of the field.</param>
164
    /// <returns>The double-precision floating point number of the specified field.</returns>
165
    public double GetDouble(int i) => _dataReader.GetDouble(i);
×
166

167
    /// <summary>
168
    /// Gets the string value of the specified field.
169
    /// </summary>
170
    /// <param name="i">The zero-based index of the field.</param>
171
    /// <returns>The string value of the specified field.</returns>
172
    public string GetString(int i) => _dataReader.GetString(i);
×
173

174
    /// <summary>
175
    /// Gets the fixed-position numeric value of the specified field.
176
    /// </summary>
177
    /// <param name="i">The zero-based index of the field.</param>
178
    /// <returns>The fixed-position numeric value of the specified field.</returns>
179
    public decimal GetDecimal(int i) => _dataReader.GetDecimal(i);
×
180

181
    /// <summary>
182
    /// Gets the date and time data value of the specified field.
183
    /// </summary>
184
    /// <param name="i">The zero-based index of the field.</param>
185
    /// <returns>The date and time data value of the specified field.</returns>
186
    public DateTime GetDateTime(int i) => _dataReader.GetDateTime(i);
×
187

188
    /// <summary>
189
    /// Returns an <see cref="IDataReader"/> for the specified column ordinal.
190
    /// </summary>
191
    /// <param name="i">The zero-based index of the field.</param>
192
    /// <returns>An <see cref="IDataReader"/> for the specified column ordinal.</returns>
193
    public IDataReader GetData(int i) => _dataReader.GetData(i);
×
194

195
    /// <summary>
196
    /// Determines whether the specified field is set to null.
197
    /// </summary>
198
    /// <param name="i">The zero-based index of the field.</param>
199
    /// <returns><c>true</c> if the specified field is set to null; otherwise, <c>false</c>.</returns>
200
    public bool IsDBNull(int i) => _dataReader.IsDBNull(i);
2,400✔
201

202
    /// <summary>
203
    /// Gets the number of columns in the current row.
204
    /// </summary>
205
    public int FieldCount => _dataReader.FieldCount;
×
206

207
    /// <summary>
208
    /// Gets the value of the field at the specified index.
209
    /// </summary>
210
    /// <param name="i">The zero-based index of the field.</param>
211
    /// <returns>The value of the field as an <see cref="object"/>.</returns>
212
    object IDataRecord.this[int i] => _dataReader[i];
×
213

214
    /// <summary>
215
    /// Gets the value of the field with the specified name, applying the field prefix if set.
216
    /// </summary>
217
    /// <param name="name">The name of the field.</param>
218
    /// <returns>The value of the field as an <see cref="object"/>.</returns>
219
    object IDataRecord.this[string name]
220
    {
221
        get
222
        {
223
            string prefixName = _fieldPrefix != null
×
224
                ? _fieldPrefix + name
×
225
                : name;
×
226

227
            return _dataReader[prefixName];
×
228
        }
229
    }
230

231
    /// <summary>
232
    /// Releases all resources used by the <see cref="DataReaderWrapper"/> and the underlying <see cref="IDataReader"/>.
233
    /// </summary>
234
    public void Dispose() => _dataReader.Dispose();
×
235

236
    /// <summary>
237
    /// Closes the underlying <see cref="IDataReader"/>.
238
    /// </summary>
239
    public void Close() => _dataReader.Dispose();
×
240

241
    /// <summary>
242
    /// Returns a <see cref="DataTable"/> that describes the column metadata of the <see cref="IDataReader"/>.
243
    /// </summary>
244
    /// <returns>A <see cref="DataTable"/> that describes the column metadata.</returns>
245
    public DataTable GetSchemaTable() => _dataReader.GetSchemaTable();
×
246

247
    /// <summary>
248
    /// Advances the data reader to the next result, when reading the results of batch SQL statements.
249
    /// </summary>
250
    /// <returns><c>true</c> if there are more result sets; otherwise, <c>false</c>.</returns>
251
    public bool NextResult() => _dataReader.NextResult();
×
252

253
    /// <summary>
254
    /// Advances the <see cref="IDataReader"/> to the next record.
255
    /// </summary>
256
    /// <returns><c>true</c> if there are more rows; otherwise, <c>false</c>.</returns>
257
    public bool Read() => _dataReader.Read();
×
258

259
    /// <summary>
260
    /// Gets a value indicating the depth of nesting for the current row.
261
    /// </summary>
262
    public int Depth => _dataReader.Depth;
×
263

264
    /// <summary>
265
    /// Gets a value indicating whether the data reader is closed.
266
    /// </summary>
267
    public bool IsClosed => _dataReader.IsClosed;
×
268

269
    /// <summary>
270
    /// Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
271
    /// </summary>
272
    public int RecordsAffected => _dataReader.RecordsAffected;
×
273
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc