Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a setting in Visual Studio (or ReSharper) that allows you to specify what namespaces should be default and which scope they are put in?

The default for an MVC project for example is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Namespace
{
    public class Class1
    {
    }
}

but ReSharper and StyleCop complain:

All using directives must be placed inside of the namespace. [StyleCop Rule: SA1200]
Using directive is not required by the code and can be safely removed

Is there a way to make the default simply:

namespace Namespace
{
    public class Class1
    {
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
438 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can set this in Re-sharper.

Re-sharper > Options > C# > Namespace Imports > Add using directive to the deepest scope.


Update: As of VS2015 and Resharper10, this has moved. It is now under:

Code Editing > C# > Code Style > Reference qualification > Add 'using' directive to deepest scope


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...