ReSharper 2022.1 Help

Extract Global Using refactoring

This refactoring allows you to convert one or more local using directives into global using directives and move them to a new or existing file.

In the example below, we apply this refactoring to using System.Collections; in file One.cs and place the extracted using to GlobalUsings.cs.

// One.cs using System.Collections; class One { void Test(ArrayList list) { // do something } } // Two.cs using System.Collections; using System.Xml; class Two { void Test(ArrayList list, XmlReader reader) { // do something } } // GlobalUsings.cs global using System.Linq; global using System.Threading.Tasks;
// One.cs class One { void Test(ArrayList list) { // do something } } // Two.cs using System.Xml; class Two { void Test(ArrayList list, XmlReader reader) { // do something } } // GlobalUsings.cs global using System.Linq; global using System.Threading.Tasks; global using System.Collections;

Extract a global using

  1. Set the caret at a using directive or select multiple directives.

  2. Do one of the following:

    • Press Control+Shift+R and then choose Extract Global Using

    • Right-click and choose Refactor | Extract Global Using in the context menu.

    • Choose ReSharper | Refactor | Extract | Extract Global Using… in the main menu.

    The Extract Global Using dialog will open.

  3. Specify where the global using should be moved — this could be any existing .cs file in the current project or a new .cs file.

  4. To apply the refactoring, click Next.

  5. ReSharper will remove the using directives for the selected namespaces from all files in the project (because a local using becomes redundant as soon as a global using appears for the same namespace) and add these directives as global using directives to the specified file.

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is not available in Visual Basic .NET

Feature is not available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

Last modified: 21 July 2022