ReSharper Help

Attributes Style

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

  1. Go to ReSharper | Options | Code Editing | C# | Code Style.
  2. In the Attributes category select the value for the Join or separate attributes in section according to your coding practices/standards.
  3. 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.
  4. 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

  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 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:

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

See Also

Last modified: 21 September 2015