ReSharper 2016.1 Help

Generating Formatting Members

ReSharper | Edit | Generate Code | Formatting Members
Alt+Insert | Formatting Members
ReSharper_GenerateFormattingMembers

Any type in .NET implements the ToString() method, which returns a string representation of the object of that type. To return a meaningful string for our types, we often need to override the ToString() method.

ReSharper allows you to automate this routine with the Generate formatting members command.

In the example below, this command is used to generate the ToString() method based on _radius and _center fields.

Before generationAfter generation
class Circle { int _radius; Point _center; }
class Circle { int _radius; Point _center; public override string ToString() { return string.Format("Radius: {0}, Center: {1}", _radius, _center); } }

To create formatting members for your type

  1. In the editor, set the caret within a class.
  2. Press Alt+Insert or choose ReSharper | Edit | Generate Codeā€¦ in the main menu .
  3. In the Generate pop-up menu, select Formatting Members.
  4. In the Generate dialog box that appears, select fields and/or auto-properties to be used in the ToString() override.
    Generating 'ToString()' with ReSharper
  5. Click Finish to complete the wizard.
    You can also click Options to review or modify commmon code generation preferences on the Code Editing | Members Generation page of ReSharper options

You can also generate the override by choosing Overriding Members in the Generate menu, but in this case the override will return base.ToString().

This feature is supported in the following languages/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts Protobuf JSON
feature_available feature_available

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

See Also

Last modified: 19 August 2016