- 2 min to read
This Code Provider is used to add a get or set accessor to a property which does not have one.
Add Getter/Setter is a cascading Code Provider. This means that the Code Provider affects all descendants implementing the property and ancestors from which the property was inherited.
Available when the caret is located within the property block.
Place the caret inside the property block as shown in the code below.
The blinking cursor shows the caret's position at which the Code Provider is available.
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- Select Add Getter or Add Setter from the menu.
After execution, the getter/setter is added to the property. If the property already contains the opposite accessor, the Code Provider will try to guess the private variable name linked with the property and populate the getter body with the return statement or setter body with the assignment of the corresponding local variable. Otherwise, the generated getter/setter will throw the NotImplementedException exception.