0

Given the following code:

var x = new myObject() {
  prop3 = 8,
  prop1 = 5,
  prop2 = 6
}

Ideally, I would like to use ReSharper or built-in IDE features to sort the properties above so that they appear like this:

var x = new myObject() {  
  prop1 = 5,
  prop2 = 6,
  prop3 = 8
}

Outside of that, I'd be open to a lightweight extension--CodeMaid was way too heavy and overlaps with too many ReSharper functions.

Jazimov
  • 12,626
  • 9
  • 52
  • 59

2 Answers2

1

You can use the built-in feature in Visual Studio for this:

  1. Select all properties.
  2. Edit > Advanced > Sort Lines

Each assignment has to be on one single line though.

Kristoffer Jälén
  • 4,112
  • 3
  • 30
  • 54
  • Unfortunately, this sorts the properties in alphabetical order. I thought you could manually decide how to sort them. – Stan1k Jan 19 '21 at 11:29
0

I don't think you can do it with ReSharper but if all your properties are on separate lines then you could use the CodeMaid extension and use its Sort Lines functionality (CTRL+M,F9) - You would need to fix the commas as it is just a text sort and doesn't have any understanding of syntax.

Piers Myers
  • 10,611
  • 6
  • 46
  • 61