You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When exporting a complex class containing nested objects, it is hard, and sometime impossible to control the ordering of columns (at least using attributes - let me know if there's another way to do this using class maps).
The main reason is because [Index] is treated as a global value.
Consider this example:
publicclassMainContent{[Index(0)]publicintId{get;set;}[Index(1)]publicintName{get;set;}[Index(2)][HeaderPrefix("First_")]publicRangeFirstRange{get;set;}[Index(3)][HeaderPrefix("Second_")]publicRangeSecondRange{get;set;}[Index(4)]publicstringComment{get;set;}}publicclassRange{[Index(0)]publicintFrom{get;set;}[Index(1)]publicintTo{get;set;}}// Using the types aboveStringBuildersb=newStringBuilder();StringWritersw=newStringWriter(sb);using(varcsv=newCsvWriter(sw,CultureInfo.InvariantCulture)){csv.WriteHeader(typeof(MainContent));csv.Flush();}Console.WriteLine(sb);
The column order I want to achieve is the following: Id, Name, First_From, First_To, Second_From,Second_To,Comment
But what I get is this Id,First_From,Second_From,Name,First_To,Second_To,Comment
I guess it's sort of expected, since we now have 3 columns with Index=0 (Id, First_From, Second_From) but it's
Describe the solution you'd like
I can think of three possible solutions
Similar to [HeaderPrefix] - add a [IndexOffset] attribute that translates the local index of the nested object to unique value
Treat [Index] as class local value.
Add a new attribute [Order(n)], or [ExportIndex(n)] that is similar to [Index] that only controls ordering within the class during export.
The text was updated successfully, but these errors were encountered:
When exporting a complex class containing nested objects, it is hard, and sometime impossible to control the ordering of columns (at least using attributes - let me know if there's another way to do this using class maps).
The main reason is because
[Index]
is treated as a global value.Consider this example:
The column order I want to achieve is the following:
Id, Name, First_From, First_To, Second_From,Second_To,Comment
But what I get is this
Id,First_From,Second_From,Name,First_To,Second_To,Comment
I guess it's sort of expected, since we now have 3 columns with
Index=0
(Id, First_From, Second_From) but it'sDescribe the solution you'd like
I can think of three possible solutions
[HeaderPrefix]
- add a[IndexOffset]
attribute that translates the local index of the nested object to unique value[Index]
as class local value.[Order(n)]
, or[ExportIndex(n)]
that is similar to[Index]
that only controls ordering within the class during export.The text was updated successfully, but these errors were encountered: