Visual Studio or Resharper functionality for place

2019-01-07 09:08发布

I like to put my using directives inside the current namespace, and not outside as VS and Resharper per default puts them.

Does anyone know of a macro/standard functionality that sorts/removes unused using directives and puts them inside the current namespace?

6条回答
【Aperson】
2楼-- · 2019-01-07 09:32

A picture is worth a thousand words – thus in ReSharper 2017 and 2018:

enter image description here

查看更多
\"骚年 ilove
3楼-- · 2019-01-07 09:37

As of Resharper 9 this has moved into Code Editing => C# => Code Style => Reference Qualification => Add 'using' directive to deepest scope.

Or you can use new settings search facility and search for deepest scope. The exact setting will come up:

Add 'using' directive to deepest scope

查看更多
三岁会撩人
4楼-- · 2019-01-07 09:39

As of version 8.2, this has moved. It is now here:

Within Visual Studio
Resharper -> Options...

Then in the Options dialog
Code Editing -> C# -> Namespace Imports -> Insert using directives when necessary -> Add using directive to the deepest scope

enter image description here

查看更多
Viruses.
5楼-- · 2019-01-07 09:43

UPDATE - ReSharper 2016.1: This option is now moved to Code Editing → C# → Code Style → Add 'using' directive to the deepest scope

Have you tried the ReSharper option:

Languages → C# → Formatting Style → Namespace Imports → Add using directive to the deepest scope

I'm not sure whether R#'s code cleanup will reorder the existing ones for you though.

查看更多
不美不萌又怎样
6楼-- · 2019-01-07 09:48

I've edited my default visual studio templates to put my using directives inside the namespace.

For sorting and removing unused directives, I use Power Commands for Visual Studio 2008.

查看更多
甜甜的少女心
7楼-- · 2019-01-07 09:52

StyleCop supports ReSharper integration starting from version 4.7.

From http://stylecop.codeplex.com/:

4.7 is compatible with JetBrains R#5.1( 5.1.3000.12), R#6.0 (6.0.2202.688), R#6.1 (6.1.37.86), R#6.1.1 (6.1.1000.82) and R#7.0 (7.0.54.77)

4.7 is compatible with Visual Studio 2008, Visual Studio 2010 and Visual Studio 11

This release includes the StyleCop ReSharper plugin (compatible with ReSharper 5.1, 6.0, 6.1, 6.1.1 and 7.0)

查看更多
登录 后发表回答