MasterDetailEngineTMaster, TDetailWriteStream Method (TextWriter, IEnumerableMasterDetailsTMaster, TDetail, Int32) |
Write the specified number of records in the array to the Stream.
Namespace:
FileHelpers.MasterDetail
Assembly:
FileHelpers (in FileHelpers.dll) Version: 3.2.6
Syntaxpublic void WriteStream(
TextWriter writer,
IEnumerable<MasterDetails<TMaster, TDetail>> records,
int maxRecords
)
Public Sub WriteStream (
writer As TextWriter,
records As IEnumerable(Of MasterDetails(Of TMaster, TDetail)),
maxRecords As Integer
)
Parameters
- writer
- Type: System.IOTextWriter
The writer of the source stream. - records
- Type: System.Collections.GenericIEnumerableMasterDetailsTMaster, TDetail
The array of records to write. - maxRecords
- Type: SystemInt32
The max number of array elements to write.
Return Value
Type:
True if the operation is successful. False otherwise.
Remarks
This method only uses the stream and does not close it after using it, you must do it.
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