Code Generation

Create from Usage

With ReSharper, you can use a method/function, property, local or field variable or even a class before it's been declared. ReSharper will suggest a quick-fix (for C#) or several context actions (for VB.NET) for generating the corresponding symbol based on the usage, and then smartly adjust the declaration according to the usage context. For example, if you create a method from usage, ReSharper will not only create a method, but also detect its return type as well as the types of its parameters.

Generate Type Members

You can quickly generate different type members with ReSharper, by simply pressing Alt+Ins.

Generate Type Constructor

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.

Generate Properties

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.

Implement/Override Methods

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.

Generate Delegating Members

Delegating members provides 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.

Generate Formatting Members

In any class, you can quickly generate a ToString() override which returns a format string with any number of type fields or auto-properties.

Generate Equality Members

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.

Generate Content Tags Based on ContentPlaceHolder Tags

When you're working with web projects or applications that make use of master pages, ReSharper is able to generate Content tags in markup pages based on ContentPlaceHolder tags defined in a referenced master page. To use this feature, press Alt+Ins in a markup page that inherits from a master page.

Web Development Generate Content

To learn more about code generation and other features that ReSharper makes available to web developers, see ASP.NET and ASP.NET MVC Tools.

Configure Generation Options

You can control how new members are generated in two major ways:

  • Configure a custom naming style for different members. When there's a naming style in place, ReSharper enforces its requirements when generating new members.
  • Choose default body content for generated members. One of the three options — NotImplementedException(), returning default value, and non-compilable code — can be configured by choosing ReSharper | Options | Languages | Common | Members Generation.
Configure Generation Options

All keyboard shortcuts provided in the "Features" section are taken from ReSharper 2.x / IDEA keyboard scheme. For details on ReSharper's two default keymaps, see Documentation and Demos.