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

Declare Class

  • 2 min to read


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 easily create declarations for classes referenced in a code fragment.


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


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


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


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