Declare Method

  • 2 minutes to read


Generates a method with appropriate parameters for the selected method call. This Code Provider is useful for Test-Driven Development.



CodeRush adds a method declared in the interface to all its implementers.


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


  1. Place the caret in an undeclared method’s name.

    public static double ConvertToUSD(double amount, object source) {
        return amount / GetCurrencyRate(source);
    static void Main(string[] args) {
        double price = ConvertToUSD(10);
  2. Press Ctrl + . or Ctrl + ~ to invoke the Code Actions Menu.


  3. Select Declare Method from the menu and press Enter. The red target picker marker appears. It allows you to choose the place where the generated code can be inserted.

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


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

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

After execution, the Code Provider adds the method declaration to the class.

You can configure the default body of newly-generated methods on the Editor | <Language>| Code Actions | Code Actions Settings options page. The default value is “Throw NotImplementedException instance”. Refer to the Code Actions Settings topic for more information.



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.

Blazor Support

The Declare Method code provider is available from the @code section and markup of .razor files:

Declare Method Blazor


If a Razor code-behind file (.razor.cs) exists, the Declare Method code provider applied from Razor markup adds the declared method to it instead of the @code section.