Hi!
"Organize Members" doesn't seems to recognize a field with an initializer as a "field".
I have to following example:
C#namespace ClassLibrary1
{
using System;
using System.Collections.Generic;
using System.Linq;
public class Class1
{
private List<string> test1;
private List<string> test2 = new List<string>();
public void Call1()
{
}
public void Call2()
{
}
}
}
If I reorganize this with "StyleCop" Settings, I receive this as a result:
C#namespace ClassLibrary1
{
using System;
using System.Collections.Generic;
using System.Linq;
public class Class1
{
private List<string> test1;
public void Call1()
{
}
public void Call2()
{
}
private List<string> test2 = new List<string>();
}
}
I can move the field up and down in the configuration and the field changes his position. Only test2 is always put at the end.
Thanks
Silvio
Hello Silvio,
Thank you for providing the code sample.
We have an option to skip initialized fields. It is enabled by default and initialized fields are not moved into the 'fields' group.
I have attached a screencast that illustrates how to disable this option. In this case, you will get the required behavior.
The reason of adding this option - a field initializer can contain references to other fields. In this case, we should not change the order of fields.
However, in your case, the field initializer is object creation, so we think that we should move such initialized fields into the 'fields' group ever if the 'Skip initialized fields' option is enabled.
We will research this issue and let you know as soon as we make any progress.