MasterDetailEngineTMaster, TDetailReadFile Method |
Read a file and return an array of the contained records.
Namespace:
FileHelpers.MasterDetail
Assembly:
FileHelpers (in FileHelpers.dll) Version: 3.2.6
Syntaxpublic MasterDetails<TMaster, TDetail>[] ReadFile(
string fileName
)
Public Function ReadFile (
fileName As String
) As MasterDetails(Of TMaster, TDetail)()
Parameters
- fileName
- Type: SystemString
The file path to be read.
Return Value
Type:
MasterDetailsTMaster,
TDetailAn array of the records in the file
Remarks
This method opens, reads and closes the file (don't open or close the file before or after calling this method)
Examples
You need to define a Selector Method too:
RecordAction ExampleSelector(string record)
{
if (Char.IsLetter(record[0]))
return RecordAction.Master;
else
return RecordAction.Detail;
}
Finally you must to instantiate a MasterDetailEngine and Read/Write files:
MaterDetailEngine engine = new MaterDetailEngine(typeof(Customers), typeof(Orders), new MasterDetailSelector(ExampleSelector));
MasterDetail[] res = engine.ReadFile("TestIn.txt");
engine.WriteFile("TestOut.txt", res);
See Also