Ryan Gates
Ryan Gates

Reputation: 4539

Adding usings inside the namespace

Is there a way to configure ReSharper to add using references to a file within the appropriate namespace?

Currently it adds them to the top of the file, which is fine, until you want multiple namespaces in the same file.

For example, I would like it to be like the following:

namespace A
{
    using System;

    // other classes
}

Upvotes: 4

Views: 2868

Answers (2)

Chris
Chris

Reputation: 637

Just to bring an up to date answer here as I was wanting to do this but not having R# (ReSharper) installed...

Its now available from Visual Studio 2019 directly since the 16.1 Release.

I found this on developercommunity.visualstudio.com

The code style to include using directives inside or outside a namespace was added in Visual Studio 2019 update 16.1. You can now set your preference in Tools > Options > Text Editor > C# > Code Style or in an EditorConfig file and the IDE can apply it through messages, warnings, or errors depending on the severity you specify in the code style rule

Upvotes: 3

Ian R. O'Brien
Ian R. O'Brien

Reputation: 6920

Options > Code Editing > C# > Namespace Imports:

Insert using directives when necessary > Add using directive to the deepest scope.

Namespace Imports

Upvotes: 8

Related Questions