Home > Blockchain >  To global using directive refactoring
To global using directive refactoring

Time:11-16

I would like to migrate my projects to .NET 6 and C# 10. As a part of this migration I would like to use global using directives.

Has Visual Studio 2022 any tool or help to do a "to global using directive" refactoring?

CodePudding user response:

I don't think, there is any tool which does "To global using" directive refactoring, but you can try alternate way,

  1. Replace using block with empty string in entire project, you can use Ctrl Shift H

enter image description here

  1. Now you can add global using in any .cs file or you put all global using in a separate file called globalusings.cs

Note:

  • Find Replace will add additional empty line in all .cs files.

CodePudding user response:

Making namespace global should render corresponding using unnecessary in other files. Remove unnecessary usings diagnostic allows you to select the scope for the fix:

enter image description here

If for some reason the diagnostic is not shown you can enable it via .editorconfig via rule code (IDE0005):

# IDE0005: Using directive is unnecessary.
dotnet_diagnostic.IDE0005.severity = suggestion
  • Related