The requested page is not available for the requested platform. You are viewing the content for Default platform.

Declare Interface

  • 2 min to read

Purpose

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.

Note

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

Availability

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

Usage

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

    Note

    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;
            Andrew.SaveToDB();
        }
    }
    
  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; }
}
Note
  • You can configure where to place the newly-generated type declarations. The possible options are: Above the current type, Below the current type, or Create a new file. Open the Editor | <Language> | Code Actions | Code Actions Settings options page to change this option.

  • 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.