DataReaderDecoratorExtensions Class
Definition
- Assemblies
- Cuemon.Data.dll
Extension methods for the IDataReader interface hidden behind the IDecorator<T> interface.
public static class DataReaderDecoratorExtensions
- Inheritance
-
DataReaderDecoratorExtensions
Examples
DataReaderDecoratorExtensions provides extension methods on Decorator.Enclose for converting IDataReader content into encoded strings or streams, both synchronously and asynchronously. This example creates a single-column DataTable with three rows of data, then wraps a fresh DataTableReader for each call to ToEncodedString, ToEncodedStringAsync, and ToStream. Console output shows the string representation of the data and the stream length.
// Program.cs
using System;
using System.Data;
using System.IO;
using System.Threading.Tasks;
using Cuemon;
using Cuemon.Data;
var table = new DataTable();
table.Columns.Add("Value", typeof(string));
table.Rows.Add("1001");
table.Rows.Add("1002");
table.Rows.Add("1003");
using (var reader = table.CreateDataReader())
{
string result = Decorator.Enclose((IDataReader)reader).ToEncodedString();
Console.WriteLine(result);
}
using (var asyncReader = table.CreateDataReader())
{
string asyncResult = await Decorator.Enclose((IDataReader)asyncReader).ToEncodedStringAsync();
Console.WriteLine(asyncResult);
}
using (var streamReader = table.CreateDataReader())
{
Stream dataStream = Decorator.Enclose((IDataReader)streamReader).ToStream();
Console.WriteLine($"Stream length: {dataStream.Length}");
}
Methods
| Name | Description |
|---|---|
| ToEncodedString(IDecorator<IDataReader>) | Converts the enclosed IDataReader of the |
| ToEncodedStringAsync(IDecorator<IDataReader>) | Asynchronously converts the enclosed IDataReader of the |
| ToStream(IDecorator<IDataReader>) | Converts the enclosed IDataReader of the |