Multiple attributes in C# can be written in different ways: you can join several attributes in the same square brackets and/or use several square brackets for different attributes. ReSharper allows you to specify the style for multiple attributes and enforce this style in the desired scope.
In this topic:
Configuring preferences for attributes style
Your attributes style 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 of attributes style
- Go to ReSharper | Options | Code Editing | C# | Code Style.
- In the Attributes category select the value for the Join or separate attributes in section according to your coding practices/standards.
- You can also configure whether to place attributes on the same line with the declaration or stack them on top. To configure this, open the Code Editing | C# | Formatting Style | Line Breaks and Wrapping options page, expand the Other section, and use the check-boxes next to the specific entries. Preferences for type, method, property attributes can be configured independently.
- 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.
Applying attributes style
To apply your attribute style settings 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 apply attributes style 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