ReSharper's code generation actions can create a lot of code for you: constructors to initialize any set of type members; methods and properties required by an interface you're implementing; equality checks, formatting members, and more.
For more ways of generating common code such as classes, conditional blocks and GUIDs, see code templates.
With ReSharper, you can use a method/function, property, local variable or field, or even a class before it's been declared. ReSharper will suggest a quick-fix for generating the corresponding declaration based on the usage, and then help you smartly adjust the declaration according to the usage context. For example, if you create a method from usage, ReSharper will not only create the method, but also detect its return type as well as the types of its parameters.
You can quickly generate different type members with ReSharper, by simply pressing Alt+Ins.
Select Constructor in the Generate pop-up menu, and then select the fields, auto-properties and base constructors that you wish to initialize in the constructor. Creating constructors in this way takes just a few keystrokes.
Create stubs for implementing interface/overriding inherited member functions. When a list of available methods to implement/override is provided; appropriate stubs are generated. You can generate several stubs at once by selecting several methods when prompted. Overriden properties can be made automatic.
Delegating members provide a means to encapsulate some behavior or publish methods of a class's field through the class's own interface. Specify fields and their methods, and ReSharper will generate wrapping methods in the current class.
First, select Read-only properties or Properties in the Generate menu. Second, select one or more fields when prompted in the dialog box. Voila. Optionally, you can make the new property virtual, or copy XML documentation from field declarations.
In any class, you can quickly generate a ToString()
override which
returns a
format string with
any number of type fields or auto-properties.
Quickly generate Equals()
and GetHashCode()
method for the current type. ReSharper not only creates the
methods, but also generates the necessary code for an equality check and/or for
calculating
hash code.
In addition, ReSharper can generate equality and inequality operators, or strongly typed
IEquatable<T>
interface.
You can control how new members are generated in several ways.
First, you can configure a custom naming style for different members. When there's a naming style in place, ReSharper enforces its requirements when generating new members.
The rest of the options can be configured in ReSharper | Options | Code Editing | Members
Generation.
For example, you can choose one of the options for the default body content of the
generated
members:
NotImplementedException()
, returning default value, and non-compilable
code.
All keyboard shortcuts provided in this page are available in ReSharper's default "Visual Studio" keymap. For details on ReSharper's two keymaps, see ReSharper Documentation.