JetBrains Rider 2024.2 Help

Convert to 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. JetBrains Rider analyzes all files in the current project, finds the same using in Two.cs, and moves both of them 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;

Convert to a global using

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

  2. Do one of the following:

    • Press Ctrl+Alt+Shift+T and then choose Convert to Global Using.

    • Choose Refactor | Convert to Global Using from the main menu.

    The Convert to 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. Optionally, select other frequently used using directives in the current project to convert them to global usings as well.

  5. To apply the refactoring, click Next.

  6. JetBrains Rider 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.

JetBrains Rider: 'Convert to Global Using' refactoring
Last modified: 23 September 2024