Declare Class

Purpose

Generates a class for reference to a non-existent class and adds the class members referenced from the initial code to it. The class is declared in a new source code file. 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 classes referenced in it.

Note

The Declare Class Code Provider also declares class members called from the initial code.

Availability

Available on a class name if the class does not exist.

Usage

  1. Place the caret on a non-existent class name in its construction.

    Note

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

    //Filename: Program.cs
    class Program {
        static void Main() {
            var 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 Class from the menu.

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

//Filename: Customer.cs
public class Customer {
    public Customer(string param1, string param2) {
    }
    public void SaveToDB() {
        throw new NotImplementedException();
    }
    public 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.