ReSharper Help

Arranging Modifiers

C# modifiers of types and type members can be written in any order. However, arranging them in the similar way throughout your code is a good practice, which improves code readability. Besides the order of modifiers, you may prefer using or not using the private and internal modifiers explicitly.

ReSharper helps you arrange modifiers in the existing code and applies your preferences for modifiers when it produces new code with code completion and code generation features, applies code templates and performs refactorings.

In this topic:

Configuring preferences for modifiers

Your modifiers order preferences are saved using the mechanism of shared settings, Among other things, this mechanism allows you to maintain different preferences for different solutions as well as to keep these preferences under a VCS and automatically share them with your team members.

To configure preferences for modifiers

  1. Go to ReSharper | Options | Code Editing | C# | Code Style.
  2. In the Modifiers category, specify the desired order of modifiers and set the preferences for explicit using of private and internal modifiers. Use the Arrange modifiers in existing code check box to specify whether you want to arrange modifiers with the code cleanup.
  3. Click Save to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.

Arranging modifiers in the existing code

To apply your preferences for modifiers in the desired scope, use code cleanup.

To apply attributes style with code cleanup

  1. Select the scope where you want to reformat code:
    • Make a selection in the editor to reformat code in the selection.
    • Set the caret anywhere in the file to reformat code in the file.
    • Select one or more items in the Solution Explorer to reformat code in these items and their child items.
  2. Do one of the following:
    • Choose ReSharper | Tools | Cleanup Code on the main menu.
    • Press Ctrl+Alt+F.
    • Right-click anywhere in the text editor or right-click the selection and choose Cleanup Code in the context menu.
  3. In the Code Cleanup dialog box that opens, select the Default: Reformat Code in the Available Profiles area.
  4. Click Run. ReSharper will reformat code in the selected scope according to your formatting preferences.

If you want to arrange modifiers without opening the Code Cleanup dialog box, you can bind the default Reformat Code profile to the silent cleanup and run it simply by pressing Ctrl+Shift+Alt+F. You can also create a custom cleanup profile that would combine applying attributes style with other code style tasks.

This feature is supported in the following languages/technologies:

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

See Also

Last modified: 21 September 2015