Declare Class
- 2 minutes to read
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 easily create declarations for classes referenced in a code fragment.
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
Place the caret in a non-existent class name in its construction.
NOTE
The blinking cursor shows the caret's position at which the Code Provider is available.
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- Select 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
using System;
namespace ConsoleApp
{
public class Customer
{
public Customer(string str1, string str2)
{
}
public void SaveToDB()
{
throw new NotImplementedException();
}
public int Age {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
}
}
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.