Search code examples
c#visual-studiovisual-studio-extensionsadd-on

Visual Studio Extension for sorting field assignments


When various objects have many fields in them it is sometimes a daunting task to ensure that you've assigned all fields properly especially when having to maintain someone else's code or simply going through a project cleanup. Is there a tool or extension for visual studio that can be used to sort fields assignments alphabetically by the object's field names as following:

From

ObjectName obj = new ObjectName
{
    SecondField = anotherObject.SecondField,
    ThirdField  = anotherObject.ThirdField,
    FirstField  = anotherObject.FirstField
};

to

ObjectName obj = new ObjectName
{
    FirstField  = anotherObject.FirstField,
    SecondField = anotherObject.SecondField,
    ThirdField  = anotherObject.ThirdField
};

I usually avoid this issue by using a simple Ctrl+Space when assigning each field which brings up an alphabetic list of fields to assign then I assign everything in a sorted manner.


Solution

  • Is there a tool or extension for visual studio that can be used to sort fields assignments alphabetically by the object's field names

    You can try to use the Visual Studio extension CodeMaid to sort object's field names:

    enter image description here

    enter image description here

    For more details, please visit: http://www.codemaid.net

    Hope this helps.