Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Columns to not appears as they are declared #32

Open
alecchan opened this issue Sep 30, 2014 · 0 comments
Open

Columns to not appears as they are declared #32

alecchan opened this issue Sep 30, 2014 · 0 comments

Comments

@alecchan
Copy link

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
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant