Declare Method

Purpose

Generates a method with appropriate parameters for the selected method call. 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 methods referenced in it.

Note

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

Availability

Available when the caret is on the line with an undeclared method.

Usage

  1. Place the caret on an undeclared method's name.

    Note

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

    public static double ConvertToUSD(Currency source, double amount) {
        return amount / GetCurrencyRate(source);
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Declare Method 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 method declaration to the class and throws the NotImplemented exception in it.

static double GetCurrencyRate(Currency source) {
    throw new NotImplementedException();
}

public static double ConvertToUSD(Currency source, double amount) {
    return amount / GetCurrencyRate(source);
}
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.