Convert to/Decompose Initializer
- 2 min to read
Converts a one-by-one initialization of class fields or properties to an object initializer and vice versa. The single-line initializers make your code more compact, although the one-by-one initialization can improve code readability.
Available when the cursor is on the name of the initialized object.
Place the caret on the name of the initialized object.
The blinking cursor shows the caret's position at which the Refactoring is available.
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- Select Convert to Initializer from the menu (Decompose Initializer if you are decomposing the initializer).
After execution, the Refactoring moves the fields/properties initialization to the object initializer or converts the inline initializer to the one-by-one initialization.