Declare Property

Purpose

Declares a property for the current reference to an undeclared element. This Code Provider is useful for Test-Driven Development. It allows you to easily create declarations for properties referenced in a code fragment.

Note

Property declared in the interface is automatically added to all its implementers.

Availability

Available when the caret is on an undeclared variable reference.

Usage

  1. Place the caret on an undeclared variable reference.

  2. Hit Ctrl + . or Ctrl + ~ to invoke the Code Actions Menu.

  3. Use the mouse to select Declare Property (with default body), Declare Property (auto-implemented) or Declare Property (with field) from the Declare menu and press Enter. The red target picker marker appears. It allows you to choose the place where the generated code can be inserted.

  4. Use the Up Arrow and Down Arrow keys to move the target picker.

  5. Press Enter to generate a code in the selected place.

The generated code depends on what Code Provider you selected and how the property was used in the original code. If you call the Code Provider for a variable contained in the right part of an expression, the provider will generate a read-only property; otherwise, the provider will declare a read-write property.

If you have chosen the Declare Property (with default body), the Code Provider will generate a property which throws the NotImplemented exception.

DeclarePropertyWithBody

If you have chosen the Declare Property (auto-implemented), the Code Provider will generate an auto-implemented property.

DeclareAutoProperty

If you have chosen the Declare Property (with field), the Code Provider will generate a property with a backing store.

DeclarePropertyField

You can configure the Target Picker on the Editor | All Languages | Code Actions | Target Picker options page.

TargetPicker

Note

The default visibility modifier of the generated member is configured on the Editor | <Language> | Scope Options options page. Refer to the Scope topic for details.