DsvDataReader Class
Definition
Provides a way of reading a forward-only stream of rows from a DSV (Delimiter Separated Values) based data source. This class cannot be inherited.
public sealed class DsvDataReader : DataReader<string[]>, IDataReader, IDataRecord, IDisposable
- Inheritance
-
objectDataReader<string[]>DsvDataReader
- Implements
- Inherited Members
Examples
The following example demonstrates how to read a CSV (comma-separated values) file using DsvDataReader.
using System;
using System.IO;
using System.Text;
using Cuemon.Data;
namespace MyApp.Examples
{
public sealed class DsvDataReaderExample
{
public void Demonstrate()
{
var csv = "Name,Age,City" + Environment.NewLine +
"Alice,30,New York" + Environment.NewLine +
"Bob,25,London" + Environment.NewLine +
"Charlie,35,Tokyo";
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(csv));
using var reader = new DsvDataReader(new StreamReader(stream));
Console.WriteLine($"Delimiter: {reader.Delimiter}");
Console.WriteLine("Header: " + string.Join(", ", reader.Header));
while (reader.Read())
{
Console.WriteLine($"Row {reader.RowCount}: Name={reader["Name"]}, Age={reader["Age"]}, City={reader["City"]}");
}
}
}
}
Constructors
| Name | Description |
|---|---|
| DsvDataReader(StreamReader, string, Func<string, object>, Action<DelimitedStringOptions>) | Initializes a new instance of the DsvDataReader class. |
Properties
| Name | Description |
|---|---|
| Delimiter | Gets the delimiter used to separate fields of this instance. |
| Header | Gets the header that defines the field names of this instance. |
| NullRead | Gets the value that indicates that no more rows exists. |
| Qualifier | Gets the qualifier that surrounds a field. |
| RowCount | Gets the currently processed row count of this instance. |
Methods
| Name | Description |
|---|---|
| OnDisposeManagedResources() | Called when this object is being disposed by either Dispose() or Dispose(bool) having |
| Read() | Advances this instance to the next line of the DSV data source. |
| ReadAsync() | Asynchronously advances this instance to the next line of the DSV data source. |
| ReadNext(string[]) | Advances this instance to the next record. |