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
I am using LinqToCVS to produce a number of reports in .NET 4.0 and noticed the columns do not appear in the same order as they are declared in the data type. However, after changing the target framework to .NET 4.5 the column do appear in the same order. Since, it is not practical to change the target framework of my project to .NET 4.5, the only way to ensure the columns are ordered correctly is to apply the CsvColumnAttrubute to every class property which I hoped to avoid.
I can only assume the sorting algorithm you are using in .NET 4.0 is not a stable, that is, it will not preserve the property collection order when the CompareTo returns zero.
I would like to propose a change to the way the columns are sorted to ensure the behavior is consistent and the order is preserved. Instead of using Array.Sort(m_IndexToInfo)
which seems unpredictable use the stable Linq search m_IndexToInfo = m_IndexToInfo.OrderBy(x => x.index).ToArray();
Below is the unit test used to verify my change
The text was updated successfully, but these errors were encountered:
I am using LinqToCVS to produce a number of reports in .NET 4.0 and noticed the columns do not appear in the same order as they are declared in the data type. However, after changing the target framework to .NET 4.5 the column do appear in the same order. Since, it is not practical to change the target framework of my project to .NET 4.5, the only way to ensure the columns are ordered correctly is to apply the CsvColumnAttrubute to every class property which I hoped to avoid.
I can only assume the sorting algorithm you are using in .NET 4.0 is not a stable, that is, it will not preserve the property collection order when the CompareTo returns zero.
I would like to propose a change to the way the columns are sorted to ensure the behavior is consistent and the order is preserved. Instead of using
Array.Sort(m_IndexToInfo)
which seems unpredictable use the stable Linq search
m_IndexToInfo = m_IndexToInfo.OrderBy(x => x.index).ToArray();
Below is the unit test used to verify my change
The text was updated successfully, but these errors were encountered: