coderushforroslyn-115364-coding-assistance-code-providers-add-getter-setter.md
This Code Provider is used to add a get or set accessor to a property which does not have one.
Note
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.
Press 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.
public int A {
get {
return a;
}
set {
a = value;
}
}
Public Property A As Integer
Get
Return _a
End Get
Set(value As Integer)
_a = value
End Set
End Property
See Also