Click button to edit
Events And Notification: INotifyWrite Interface
Get Before/After Write events with the INotifyWrite interface
Input.txt
10249 TOMSP 05071996 11.61
10250 HANAR 08071996 0.00
10251 VICTE 08071996 41.34
10269 TOMSP 05071996 11.61
10230 HANAR 08071996 65.83
10151 VICTE 08071996 41.34
Report layout.cs
[FixedLengthRecord]
[IgnoreEmptyLines]
public class OrdersFixed
:INotifyWrite
{
[FieldFixedLength(7)]
public int OrderID;
[FieldFixedLength(8)]
public string CustomerID;
[FieldFixedLength(8)]
public DateTime OrderDate;
[FieldFixedLength(11)]
public decimal Freight;
public void BeforeWrite(BeforeWriteEventArgs e)
{
// We only want clients with large frieght values
if (Freight < 40)
e.SkipThisRecord = true;
}
public void AfterWrite(AfterWriteEventArgs e)
{
// Hide a line
if (CustomerID.Trim() == "HANAR")
e.RecordLine = "-- Insufficient Access";
}
}
Run a record through engine using the write event to filter out unwanted details
RunEngine.cs
var engine = new FileHelperEngine<OrdersFixed>();
var result = engine.ReadFile("Input.txt");
engine.WriteFile("output.txt", result);
output.txt
10251 VICTE 08071996 41.34
-- Insufficient Access
10151 VICTE 08071996 41.34