Reputation: 4319
When using TypeAccessor.Create FastMember always seems to return a list of the columns in alphabetic sorted order. Is it possible to tell it to preserve the ordering of the columns in the class?
for example:
var testClass = new { B = "1", A = "2" };
will return column A then B from GetMembers, I'd like to get it to preserve the ordering of B then A if possible.
Upvotes: 5
Views: 1565
Reputation: 2343
I created a fork of this project with column order option and added a PR to the original repository. OrdinalAttribute
was added to specify columns order.
The ordinal attribute can be used as shown below:
public class ObjectReaderWithDefinedColumnsOrderType
{
[Ordinal(1)]
public byte C { get; set; }
[Ordinal(0)]
public int? D { get; set; }
}
IDataReader
object returned in ObjectReader.Create()
will have columns order according to the defined attributes.-1
ordinal).You can use my for right away or wait until the PR is merged with the original repository.
Upvotes: 5
Reputation: 4319
Looks like Evk is right and it can't really be done via the standard APIs. In the interest of completeness I'll leave this as the answer.
Upvotes: 2