FileHelperAsyncEngineT Class |
One of the main classes of the library.
This engine is responsible to Read/Write the records One by One from/to files or streams.
Namespace: FileHelpers
public class FileHelperAsyncEngine<T> : EventEngineBase<T>, IFileHelperAsyncEngine<T>, IEnumerable<T>, IEnumerable, IDisposable where T : class
The FileHelperAsyncEngineT type exposes the following members.
Name | Description | |
---|---|---|
![]() | FileHelperAsyncEngineT |
Initializes a new instance of the FileHelperAsyncEngine class with the specified type of records.
|
![]() | FileHelperAsyncEngineT(Encoding) |
Initializes a new instance of the FileHelperAsyncEngine class with the specified type of records.
|
Name | Description | |
---|---|---|
![]() | Encoding |
The encoding to Read and Write the streams.
Default is the system's current ANSI code page.
(Inherited from EngineBase.) |
![]() | ErrorManager | This is a common class that manages the errors of the library. (Inherited from EngineBase.) |
![]() | ErrorMode |
Indicates the behavior of the engine when it finds an error.
{Shortcut for )
(Inherited from EngineBase.) |
![]() | FooterText | The Read Footer in the last Read operation. If any. (Inherited from EngineBase.) |
![]() | HeaderText | The Read Header in the last Read operation. If any. (Inherited from EngineBase.) |
![]() | ItemInt32 |
Get a field value of the current records.
|
![]() | ItemString |
Get a field value of the current records.
|
![]() ![]() | LastRecord | Contains the last Record read by the ReadNext method. |
![]() | LastRecordValues |
An array with the values of each field of the current record
|
![]() | LineNumber | The current line number. (Inherited from EngineBase.) |
![]() | NewLineForWrite |
Newline string to be used when engine writes to file.
Default is the system's newline setting (System.Environment.NewLine).
(Inherited from EngineBase.) |
![]() | Options |
Allows you to change some record layout options at runtime
(Inherited from EngineBase.) |
![]() | RecordType | Returns the type of records handled by this engine. (Inherited from EngineBase.) |
![]() | TotalRecords | The total numbers of records in the last read/written file
(only works with whole read/write). (Inherited from EngineBase.) |
Name | Description | |
---|---|---|
![]() | BeginAppendToFile(String) |
Begin the append to an existing file
|
![]() | BeginAppendToFile(String, Int32) |
Open a file to Append to the end.
|
![]() ![]() | BeginReadFile(String) |
Open a specified file and seek to the first record.
|
![]() ![]() | BeginReadFile(String, Int32) |
Open a specified file and seek to the first record.
|
![]() ![]() | BeginReadStream |
Open a specified stream and seek to the first record.
|
![]() | BeginReadString | |
![]() ![]() | BeginWriteFile(String) |
Open a file to write it.
If the file exists the engine will over write it
|
![]() ![]() | BeginWriteFile(String, Int32) |
Open a file to write it.
If the file exists the engine will over write it
|
![]() ![]() | BeginWriteStream |
Set the stream to be used in the WriteNext(T) operation.
|
![]() ![]() | Close |
Close all opened stream readers and writers (if any).
|
![]() | Flush |
Save all the buffered data for write to the disk.
Useful to opened async engines that wants to save pending values to
disk or for engines used for logging.
|
![]() | GetFileHeader |
Builds a line with the name of the fields, for a delimited files it
uses the same delimiter, for a fixed length field it writes the
fields names separated with tabs
(Inherited from EngineBase.) |
![]() ![]() | ReadNext |
Reads the next record of a file.
|
![]() | ReadNexts |
Reads the specified number of records from a file or stream opened before.
|
![]() | ReadToEnd |
Return array of object for all data to end of the file
|
![]() ![]() | WriteNext |
Write the next record to a file or stream opened.
|
![]() | WriteNexts |
Write the next records to a file or stream opened.
|
![]() | WriteNextValues |
Write the current record values in the buffer. You can use
engine[0] or engine["YourField"] to set the values.
|
Name | Description | |
---|---|---|
![]() | AfterReadRecord |
Called in read operations just after the record was created from a
record string.
(Inherited from EventEngineBaseT.) |
![]() | AfterWriteRecord |
Called in write operations just after the record was converted to a
string.
(Inherited from EventEngineBaseT.) |
![]() | BeforeReadRecord |
Called in read operations just before the record string is
translated to a record.
(Inherited from EventEngineBaseT.) |
![]() | BeforeWriteRecord |
Called in write operations just before the record is converted to a
string to write it.
(Inherited from EventEngineBaseT.) |
![]() | Progress | Event handler called to notify progress. (Inherited from EngineBase.) |
You can set the ErrorMode of this class to find out when there is an error. Retrieve them with the Errors property.
See in the Class Diagram and in the Quick Start Guide for more Info.
Or you can browse the Examples Section for more code.
using FileHelpers; // First declare the record class [Delimitedrecord("|")] public class SampleType { public string Field1; public int Field2; } public void ReadExample() { SampleType record; var engine = new FileHelperAsyncEngine<SampleType>(); using(engine.BeginReadFile("source.txt")) { foreach(var record in engine) { // put your code here !!!! Console.WriteLine("Data " + record.Field1 + " , " + record.Field2.ToString()); } } } public void WriteExample() { SampleType record; var engine = new FileHelperAsyncEngine<SampleType>(); using(engine.BeginWriteFile("source.txt")) { record.Field1 = "Primer Registro"; record.Field2 = 1; engine.WriteNext(record); record.Field1 = "Segundo Registro"; record.Field2 = 2; engine.WriteNext(record); } }