Class ReaderExtension
Inherited Members
Namespace: DataWeb.Data.SqlServer
Assembly: DataWeb.Data.SqlServer.dll
Syntax
public static class ReaderExtension
Methods
GetBoolean(IDataReader, string)
Extracts a boolean value from a data reader field by name.
Declaration
public static bool GetBoolean(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| bool | The boolean value of the field. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if reader is null. |
| ArgumentException | Thrown if fieldName is null or empty. |
GetDecimal(IDataReader, string)
Extracts a decimal value from a data reader field by name.
Declaration
public static decimal GetDecimal(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| decimal | The decimal value of the field. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if reader is null. |
| ArgumentException | Thrown if fieldName is null or empty. |
GetDictionaryFromReader(IDataReader, string[])
Converts all columns from a data reader row into a dictionary, optionally excluding reserved field names.
Declaration
public static Dictionary<string, object> GetDictionaryFromReader(this IDataReader reader, string[] reservedFields = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader positioned on a valid row. |
| string[] | reservedFields | Optional field names to exclude from the dictionary. Case-insensitive. |
Returns
| Type | Description |
|---|---|
| Dictionary<string, object> | A case-insensitive dictionary of column names to values. |
GetFileSettings(IDataReader, string)
Deserializes a JSON field from a data reader into a FileSettings object.
Declaration
public static FileSettings GetFileSettings(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field containing the JSON settings. |
Returns
| Type | Description |
|---|---|
| FileSettings | A deserialized FileSettings object, or null if the field is null or empty. |
GetInt16(IDataReader, string)
Extracts a 16-bit integer value from a data reader field by name.
Declaration
public static short GetInt16(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| short | The short value of the field. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if reader is null. |
| ArgumentException | Thrown if fieldName is null or empty. |
GetInt32(IDataReader, string)
Extracts a 32-bit integer value from a data reader field by name.
Declaration
public static int GetInt32(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| int | The int value of the field. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if reader is null. |
| ArgumentException | Thrown if fieldName is null or empty. |
GetInt64(IDataReader, string)
Extracts a 64-bit integer value from a data reader field by name.
Declaration
public static long GetInt64(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| long | The long value of the field. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if reader is null. |
| ArgumentException | Thrown if fieldName is null or empty. |
GetNullableString(IDataReader, string)
Extracts a nullable string value from a data reader field.
Declaration
public static string GetNullableString(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| string | The string value, or null if the field contains DBNull. Empty strings are valid return values. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if reader is null. |
| ArgumentException | Thrown if fieldName is null or empty. |
GetNullableValue<T>(IDataReader, string)
Extracts a nullable value of the specified type from a data reader field.
Declaration
public static T? GetNullableValue<T>(this IDataReader reader, string fieldName) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| T? | The field value cast to |
Type Parameters
| Name | Description |
|---|---|
| T | The value type (must be a struct). |
GetString(IDataReader, string)
Extracts a non-nullable string value from a data reader field by name.
Declaration
public static string GetString(this IDataReader reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field to read. |
Returns
| Type | Description |
|---|---|
| string | The string value. Empty strings are valid return values. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if reader is null. |
| ArgumentException | Thrown if fieldName is null or empty. |
GetStringValues(IDataReader, string, char)
Splits a delimited string field from a data reader into an enumerable of strings.
Declaration
public static IEnumerable<string> GetStringValues(this IDataReader reader, string fieldName, char separator = ',')
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader to read from. |
| string | fieldName | The name of the field containing the delimited string. |
| char | separator | The character used to delimit values. Defaults to comma. |
Returns
| Type | Description |
|---|---|
| IEnumerable<string> | An enumerable of non-empty string values, or an empty enumerable if the field is null or empty. |
HasField(IDataRecord, string)
Checks whether a data reader contains a field with the specified name.
Declaration
public static bool HasField(this IDataRecord reader, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataRecord | reader | The data reader to check. |
| string | fieldName | The name of the field to search for (case-insensitive). |
Returns
| Type | Description |
|---|---|
| bool |
SetFileFields(IDataReader, IFile)
Populates the properties of an IFile object from a data reader row.
Declaration
public static void SetFileFields(this IDataReader reader, IFile file)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader positioned on a valid file data row. |
| IFile | file | The IFile object to populate. |
ToFileData(IDataReader)
Converts a data reader row to a FileData object.
Declaration
public static FileData ToFileData(this IDataReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| IDataReader | reader | The data reader positioned on a valid file data row. |
Returns
| Type | Description |
|---|---|
| FileData | A FileData object populated from the reader, or an empty instance if reader is null or IdMaster is null. |