Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper Tip/Trick... is this possible?

How can I have Resharper convert code file like

using Stuff;
using Stuff.MoreStuff;
using Stuff.MoreStuff.EvenMoreStuff;

namespace CoolStuff 
{
// src code
}

To

namespace CoolStuff 
{
  #region Using Statements
  using Stuff;
  using Stuff.MoreStuff;
  using Stuff.MoreStuff.EvenMoreStuff;
  #endregion

// src code
}

I just like it this way, it "I think" is in one of the stylecop rules too. I would appreciate any kind of help.

Thanks

like image 373
Perpetualcoder Avatar asked Jan 23 '23 15:01

Perpetualcoder


1 Answers

In your ReSharper Options, find the Namespace Imports page under C#->Formatting Style. In there, check the "Add using directive to the deepest scope" check box.

Then, go down to the bottom Tools section, and select the Code Cleanup page. Create a new cleanup profile, and check the "Embrace 'using' directives in region" option, supplying "Using Statements" as the region name on the next line. Make sure that "Optimize 'using' directives" is checked. You can turn the other cleanup settings on or off as you like.

Then, you can run code cleanup on a file by pressing Ctrl+E, C (or Ctrl+E, F if you've set that profile as your silent clean-up profile).

like image 187
bdukes Avatar answered Jan 28 '23 05:01

bdukes