Click button to edit
Attributes: FixedLengthRecord FixedMode.AllowLessChars
Options when working with fixed files where not all records have same length:
Input.txt
01010 Alfreds Futterkiste 13122005
12399 Ana Trujillo Emparedados y 23012000
00011 Antonio Moreno Taquería 042001
51677 Around the Horn 13051998
99999 Berglunds snabbköp 111999
RecordClass.cs
[FixedLengthRecord(FixedMode.AllowLessChars)]
public class Customer
{
[FieldFixedLength(5)]
public int CustId;
[FieldFixedLength(30)]
[FieldTrim(TrimMode.Both)]
public string Name;
[FieldFixedLength(8)]
[FieldConverter(ConverterKind.DateMultiFormat, "ddMMyyyy", "MMyyyy")]
public DateTime AddedDate;
}
Example.cs
var engine = new FixedFileEngine<Customer>();
Customer[] result = engine.ReadFile("input.txt");
foreach (var detail in result) {
Console.WriteLine(" Client: {0}, Date: {1}",
detail.CustId,
detail.AddedDate.ToString("dd-MM-yyyy"));
}
Console
Client: 1010, Date: 13-12-2005
Client: 12399, Date: 23-01-2000
Client: 11, Date: 01-04-2001
Client: 51677, Date: 13-05-1998
Client: 99999, Date: 01-11-1999