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
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
- Go to ReSharper | Options | Code Editing | C# | Code Style.
Modifiers category, specify the desired order of modifiers and
set the preferences for explicit using of
internalmodifiers. Use the Arrange modifiers in existing code check box to specify whether you want to arrange modifiers with the code cleanup.
- 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
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.
Do one of the following:
- Choose 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.
- In the Code Cleanup dialog box that opens, select the Default: Reformat Code in the Available Profiles area.
- 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:
- Naming Style
- Navigating Between Code Issues
- Finding Out What Is Wrong with Your Code
- Code Formatting Rules
- File and Type Layout
- File Header Style
- Namespace Imports Assistance
- Implicit/Explicit Typing
- Using Auto-Properties
- Making Fields Readonly
- Attributes Style
- Arranging Modifiers
- Arranging Optional Member Qualifiers
- Reformatting XML Doc Comments
- Removing Code Redundancies