PositionBasedDatarecords

Defining position based records

Creating a record definition for a position based record can be done like the following example:

[PositionbasedDatarecord(702)]
public class MainRecord
{
[PositionbasedDatafield(0, 2)]
public int RecordType {get; set;}

[PositionbasedDatafield(2,70, Occurrence=10)]
public SubRecord[] Personalia {get; set;}
}

[PositionbasedDatarecord(70)]
public class SubRecord
{
[PositionbasedDatafield(0,60)]
public string Name {get; set;}

[PositionbasedDatafield(60, 10, Format="dd-MM-yyyy")]
public DateTime Birthdate {get; set;}
}

This defines a main record that has fields defined by their position. It contains the following fields:
RecordType: starting at position 0 with length 2 of type int
Personalia: starting at position 2 with length 700 of type SubRecord

And it defines a SubRecord that has fields defined by their position. It contains the following fields:
Name: starting at position 0 with length 60 of type string
Birthdate: starting at position 60 with length 10 and format "dd-MM-yyyy" of type DateTime.

Using position based records

An example of the serialized representation of the record would look like the following:

"01MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011MyName                                                    13-02-2011"

The string representation of MainRecord can be deserialized to an instance of MainRecord using the DatarecordSerializer as follows:

var serializer = new DatarecordSerializer<MainRecord>();
var mainRecordInstance = serializer.Deserialize(stringRepresentationOfMainRecord);

And vice-versa an instance of MainRecord can be serialized to its string representation as follows:

var serializer = new DatarecordSerializer<MainRecord>();
var stringRepresentationOfMainRecord = serializer.Serialize(mainRecordInstance);

Last edited Oct 2, 2012 at 10:34 PM by Coilz, version 3

Comments

No comments yet.