/ Assembly List / LJCTextDataReaderLib / TextDataReader

Namespace - LJCTextDataReaderLib


Syntax

C#
public class TextDataReader : IDataReader , IDataRecord

A text file data reader.

Remarks

A class that implements IDataReader must implement the Read() and IDataRecord GetValue() methods. It must also implement the IDataRecord FieldCount property.

The GetOrdinal() method must be implemented if field name mapping is used.

The currently supported common IDataReader methods are: GetDataTypeName(int/string), GetFieldType(), GetName(), GetOrdinal(), GetSchemaTable(), GetValues(), IsDBNull() and Read().
All IDataRecord Get Type by index methods are supported including: GetBoolean(), GetInt32(), GetString(), GetValue(), etc.

Also included are custom Get Type by name method overloads to get the data values by the field name. These methods overload the IDataRecord Get Type by index methods.

This data reader expects the lines to be terminated with CR/LF. It can parse comma or tab delimited fields and can handle quoted fields.
Only use quoted fields when necessary to get a slight performance increase.

Use the LJCSetFile() method to initialize for the file to be read. This sets the LJCDataFields property with the data field definitions. Use the Read() method to read the next line values from the file.

Alternately, you can use the LJCSetLines() method if you want to process a string array. Use the LJCReadLine() method to read the next line from the string array.

The data field definition names can be parsed from the file heading line. This can be accomplished in two ways:
1. When creating the TextDataReader, set the hasheadingLine constructor property to 'true' or leave it blank to let it default to 'true'.
2. After creating the TextDataReader, you can set the LJCHasHeadingLine property to 'true'. This must be done before calling the LJCSetFile() or LJCSetLines() method.

The data fields can be in a fixed length format. This can be set in two ways:
1. When creating the TextDataReader, set the fixedLengthFields constructor property to 'true'.
2. After creating the TextDataReader, you can set the LJCFixedLengthFields property to 'true'. This must be done before calling the LJCSetFile() or LJCSetLines() method.
The field MaxLength and DataTypeName can be included in the file heading line. The formats are: Name|MaxLength or Name|MaxLength|DataTypeName. The MaxLength value is required for fixed length fields.

The data field definitions can also be loaded from an XML layout file.
Use the LJCSetFields() method to initialize the data field definitions from an XML data definition file. This file uses the DbColumns format.
Set LJCHasHeaderLine to 'false' before calling LJCSetFile() or LJCSetLines().
The MaxLength and Position values are required for fixed length fields.
The field names can be retrieved with the LJCGetFieldNames() method.

The Read() or LJCReadLine() methods set the next line values in the LJCDataFields property. A field value can be retrieved by index or field name as in object value = textDataReader[1]; or value = textDataReader["Name"];. A value can also be retrieved as a specific type by index or name using the Get Type methods such as GetBoolean(), GetInt32(), GetString(), GetValue(), etc.

A Data Object can be populated with the field values using the LJCSetObjectValues() method.

Public Methods
#ctor Initializes an object instance.
Close Closes the data reader.
Dispose Disposes the object.
GetBoolean Returns the bool value of the data field at the specified index.
GetBoolean Returns the bool value of the data field with the specified name.
GetByte Returns the byte value of the data field at the specified index.
GetByte Returns the byte value of the data field with the specified name.
GetBytes Place bytes from field at the specified index into a byte array buffer.
GetBytes Place bytes from field with the specified name into a byte array buffer.
GetChar Returns the char value of the data field at the specified index.
GetChar Returns the char value of the data field with the specified name.
GetChars Place characters from field at the specified index into a character array buffer.
GetChars Place characters from field with the specified name into a character array buffer.
GetData Not supported. Currently returns null.
GetDataTypeName Retrieves the data type name for the specified field index.
GetDataTypeName Retrieves the data type name for the specified field name.
GetDateTime Returns the DateTime value of the data field at the specified index.
GetDateTime Returns the DateTime value of the data field with the specified name.
GetDecimal Returns the decimal value of the data field at the specified index.
GetDecimal Returns the decimal value of the data field with the specified name.
GetDouble Returns the double value of the data field at the specified index.
GetDouble Returns the double value of the data field with the specified name.
GetFieldType Retrieves the type of the field for the specified field index.
GetFloat Returns the float value of the data field at the specified index.
GetFloat Returns the float value of the data field with the specified name.
GetGuid Returns the Guid value of the data field at the specified index.
GetGuid Returns the Guid value of the data field with the specified name.
GetInt16 Returns the short int value of the data field at the specified index.
GetInt16 Returns the short int value of the data field with the specified name.
GetInt32 Returns the int value of the data field at the specified index.
GetInt32 Returns the int value of the data field with the specified name.
GetInt64 Returns the long int value of the data field at the specified index.
GetInt64 Returns the long int value of the data field with the specified name.
GetName Retrieves the name of the data field with the specified index.
GetOrdinal Retrieves the index of the data field with the specified name. (DE)
GetSchemaTable Gets the Schema DataTable object.
GetString Returns the string value of the data field at the specified index.
GetString Returns the string value of the data field with the specified name.
GetValue Returns the object value of the data field at the specified index. (DE)
GetValues Gets an array of record values.
IsDBNull Indicates if the field value is null or whitespace.
LJCGetFieldNames Returns the field names.
LJCReadLine Reads the next line from the line string array. (DE)
LJCSetFields Sets the DataFields layout from an XML file. (E)
LJCSetFile Sets the source text file values. (E)
LJCSetLine Sets the line field values.
LJCSetLines Set the source line string array. (RE)
LJCSetNames Sets the data field names.
LJCSetObjectValues Sets the data object property values from the TextDataReader. (RE)
LJCSetStartIndex Sets the starting record index.
LJCSetValues Sets the current, fixed length, line values.
LJCSetValues Sets the current line values.
NextResult Sets to the next result. Currently returns false.
Read Reads the next line of the text file. (DE)
54 Methods

Properties
Depth Currently returns 0.
FieldCount Gets the field count.
IsClosed Indicates if the reader is closed.
Item Gets the data field value for the specified field index.
Item Gets the data field value for the specified field name.
LJCCurrentLineIndex Gets or sets the Current Line index.
LJCCurrentRecordCount Gets or sets the Current RecordCount value.
LJCDataFields Gets or sets the current DataField values.
LJCFieldDelimiter Gets or sets the field delimiter.
LJCFileName Gets or sets the FileName value.
LJCFixedLengthFields Gets or sets the FixedLength fields indicator.
LJCHasHeadingLine Gets or sets the HasHeadingLine value.
LJCLineOffsets Gets the LineOffsets collection.
LJCLines Gets or sets the Lines value.
LJCPageSize Gets or sets the PageSize value.
LJCPageStartIndex Gets or sets the PageStart index.
LJCSkipHeaderLines Gets or sets the number of lines to skip.
LJCStream Gets the Stream value.
LJCStreamReader Gets or sets the StreamReader value.
RecordsAffected Currently returns -1.

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.