ReSharper 8.0 Web Help

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 a custom type, we often need to override the ToString() method.

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


You can set up common code generation options in the ReSharper | Options | Code Editing | Members Generation.

To create formatting members for your type
  1. In the editor, place the caret within a class.
  2. On the main menu, choose ReSharper | Edit | Generate Code, or press Alt+Insert.
  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 wrapped with the ToString() override.
    Generating formatting members
  5. Click Finish to complete the wizard.

ReSharper will generate the override returning a format string with selected fields:


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


To bind any code generation command to its own shortcut, go to Tools | Options | Environment | Keyboard and look for commands starting with ReSharper_Generate.

This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
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 the corresponding topics in the ReSharper by Language section.