Is there a way to remove unnecessary "using" statements from a class?
For example I might have a complex class in which I might add my own namespaces but there are also some namespaces that are added automatically by Visual Studio which I also might be using:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Navigation;
using System.IO.IsolatedStorage;
using Microsoft.Phone.Shell;
using System.Net.NetworkInformation;
using System.ServiceModel.Syndication;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Phone.Controls;
using Telerik.Windows.Controls;
using MyApp.Models;
using MyApp.Services;
Is there a way to detect which namespaces are being used and which ones aren't so they can be removed?
NOTE: I believe this question would apply to any platform (Desktop, Phone, Web, etc).
Yes - Visual Studio can do this for you. In the context menu in the text editor, choose Organize Usings > Remove and Sort. (You can just remove, but why not sort at the same time? :)
Personally I have it on a hotkey of Ctrl-Shift-U... it's a very handy feature.
As a side note, these aren't using
statements - they're using
directives. using
statements are the ones which dispose of resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With