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 default behavior).


This code provider can drop a marker onto the initial interface reference, if the interface is created in a new file (the default behavior) and the Markers feature is enabled.

See the following topic section for more details: Markers: How to Enable


Available when the caret is on the interface name if the interface declaration 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. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select 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; }


Change Code Actions Settings

You can configure the Declare Interface code provider settings on the Editor | C# (Visual Basic) | Code Actions | Code Actions Settings options page.


For example, specify the “Position of newly-generated type declarations” setting to configure where CodeRush should place the newly-generated type declarations. The possible options are:

  • Above the current type
  • Below the current type
  • Create a new file (the default value)

For more information, refer to the following topic: Code Actions Settings.

Change Scope

You can also change the default visibility modifier of the generated type and its members on the Editor | C# (Visual Basic) | Scope Options options page.


See the following topic for details: Scope.