Quick ways to add and remove a set/get property accessor with CodeRush
A property without a ‘set’ accessor is considered read-only:
You can not assign a value to this property until you have a ‘set’ accessor to this property. The set accessor is similar to a void method with an implicit parameter called value, whose type is the type of the property. If a property does not yet have a set accessor, you can easily add it using the Add Setter code provider:
As a result, a property has a read-write access:
The code provider will automatically determine the field reference used as a backing store and assign a value to it.
You can also perform the opposite operation – convert a read-write property to a read-only property by using the corresponding Remove Setter code provider. The code provider is available when a value is never assigned to a property. In other words, the code provider safely removes the set accessor if it is not referenced in the code:
The latter code provider is useful to refactor and cleanup your code, eliminating undesirable property use.
If the property is write-only, having only the setter accessor, you can use the Add Getter code provider, which is similar to the Add Setter, but adds the getter accessor instead:
—– Products: CodeRush Pro Versions: 12.1 and up VS IDEs: 2008 and up Updated: Aug/30/2012 ID: C174