I downloaded FileHelpers from nuget but I am not sure if this feature does not exist or if I don’t have the right version or what.
I been looking around and it seems that FileHelpers may have an attribute to specify the field order.
I downloaded this one however when I was looking in nuget there seems to be another version
Firstly, the FieldOrder attribute does not exist in FileHelpers 2.0. In FileHelpers 2.9.9 (also available via NuGet), the attribute exists but if you specify it for any field, you must specify it for all fields. In general, however, use of the attribute is no necessary, since the order of the fields is defined by the format.
When using FileHelpers you provide a class to describe your format, e.g.,
This describes a format with three fields, separated by vertical bars. If you like, it is the specification of the format. Once defined you can use it to import and export:
So, if you want your fields in a different order, you should modify your
Orderclass.Now if you really wanted to, (with FileHelpers 2.9.9), you could change the order of the fields as follows:
but it is cleaner to avoid the use of the
FieldOrderattribute and modify the order of the fields within the class instead.On the other hand, if you need to specify the field order at runtime, you should build the
Orderclass at using runtime records. You can use astringOr you can use a
ClassBuilder:You can use whatever logic you like in order to add your fields in the necessary order.