Declare Property with Initializer

Purpose

Declares a property for the current parameter and initializes it. This Code Provider is especially useful for Test-Driven Development. It allows you to first write a code fragment and then easily create declarations for properties referenced in it.

Note

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

Availability

Available when the caret is on a method parameter within the method signature.

Usage

  1. Place the caret on an undeclared parameter.

    Note

    The blinking cursor shows the caret's position at which the Code Provider is available.

    bool DeleteRecord(int ID) {
        // ...
        return true;
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Declare | Declare Property with Initializer from the menu.
  4. Choose the desired location of the generated code using the Up Arrow and Down Arrow keys and press Enter to confirm it.

After execution, the Code Provider adds the auto-implemented property to the current class and assigns the parameter value to it.

public int ID { get; set; }
bool DeleteRecord(int ID) {
    this.ID = ID;
    // ...
    return true;
}