I have been struggling with dumping a list<T> as a grid
I have a List<T> that consists of a variable number of class objects with properties. The List<T> initializes as expected with N objects - and if I debug the List<T> the properties are all there for each.
But, When I Dump() the list, the properties do not come out in the order of declaration. Is there a way to be sure that properties in the grid will match to the declaration order?
For example:
[Serializable] **public class YsListMe : List<**Y**>** { } **public class Y** { public string Prop1{ get; set; } public string Prop1Label { get; set; } = ""; public string Prop2 { get; set; } public string Prop2Label { get; set; } =""; } var dt= new Y() { Prop1="10"; Prop1Label="foo1"; Prop2="1000"; Prop2Label="foo2"; }
comes out as:
10, 0, foo1, foo2
when I expected it to be
10, foo1, 0, foo2
Is the order of assignment in the constructor to blame? If I do this instead, for example, will this generate the order of items ?
var dt= new Y() { // values Prop1="10"; Prop2="1000"; // labels Prop1Label="foo1"; Prop2Label="foo2"; }
Comments
-
Or is it by data type?
-
The properties should come out in order of declaration. Which version of LINQPad are you using?
What do you see when you reflect the query in ILSpy?
-
Strange.
The default order should be defined by Edit/Preferences/Results/Column Ordering
Your example does not compile, but it looks like in your case they should both be the same.