Sorting enum entries Follow
I ran across the same problem as several other people:
http://stackoverflow.com/questions/7038543/sort-enum-items-in-editor
I have a huge list of enum values and the desire to sort them. There are work-arounds by using other editors, but it'd be nice to have "sort by name" and "sort by value/integer" as an Alt+Enter option on the enum Name.
This action should probably come with a warning. There is a small chance that the programmer uses the implied integer in an enum, without assigning a specific integer
E.g. (int)DayOfTheWeek.Sunday, where the enum DayOfTheWeek does not have explicit integer assigned.
In this case, a warning would allow them to check for uses to ensure that sorting would not cause a problem.
As a special case, I often leave the first value as a default (although I wouldn't be that upset if it was sorted into the list):
Before sort:
public enum Yum
{
Default = 0, // or something "None"
// <summar> b is the greatest </summary>
b,
a = 6,
d = 4,
c, e, f, g
}
After sort by name:
public enum Yum
{
//Default = 0, <-- if you preserved the first value, then "Default = 0" would remain here
a = 6,
// <summar> b is the greatest </summary>
b,
c,
d = 4,
Default = 0, // <-- if you do not preserved the first value, then "Default = 0" would move here
e,
f,
g,
}
Please sign in to leave a comment.