Declare Interface

  • 2 minutes to read


Generates an interface for reference to a non-existent type and adds the interface members referenced from the initial code to it. The interface is declared in a new source code file.


The Declare Interface also declares interface members called from the initial code.


Available on the name of an interface if it does not exist.


  1. Place the caret on a reference to non-existent interface.


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

    //Filename: Program.cs
    class Program {
        static void Main() {
            IPerson Andrew = new Customer("Andrew", "Fuller");
            Andrew.Age = 47;
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.

  3. Select Declare | Declare Interface from the menu.

After execution, the Code Provider adds a new file to the project and declares the interface in it.

//Filename: IPerson.cs
public interface IPerson {
    void SaveToDB();
    int Age { get; set; }
  • You can configure where CodeRush should place the newly-generated type declarations. The possible options are: Above the current type, Below the current type, or Create a new file. Refer to the Code Actions Settings topic for more information.

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