Purpose
Removes the unused references and optionally sorts them.
Availability
Available when the cursor is on a using (Imports) keyword assuming the source code file contains unused references.
Usage
Place the caret on a using (Imports) keyword.
NOTE
The blinking cursor shows the caret's position at which the Refactoring is available.
using│ System;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Diagnostics.Contracts;
Imports│ System.Windows.Forms
Imports System.Threading.Tasks
Imports System.Text
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Diagnostics.Contracts
<ResourceDictionary│
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:Controls="clr-namespace:DevExpress.SalesDemo.Wpf.Controls">
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- Select Optimize Namespace References from the menu.
After execution, the Refactoring sorts the namespace references alphabetically.
using System;
using System.Diagnostics.Contracts;
using System.Windows.Forms;
Imports System.Diagnostics.Contracts
Imports System.Windows.Forms
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:DevExpress.SalesDemo.Wpf.Controls">
Configuration
If you prefer sorting references by length or you want to disable automatic sorting, change these parameters in the Editor | All Languages | Namespace References options page.
In this configuration section, you can also configure the list of namespaces that should never be removed by the Optimize Namespace References Refactoring.
See Also