Reputation: 127
I'm a complete newb. I see that these using statements or references at the top of the page are a pain to manage. Is there a way to reference these in a class or some other file and have a single statement at the top of the form code or in a logic file?
Ex: Make this
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Windows.Forms;
into this
using Class : FileName
Or some other form of reference.
Not having fully mapped the program I frequently move things to the logic files. Occasionally I get an error such as Are you missing a using directive or namespace
. Usually I see I'm missing something that was where I created the function but is missing where the function now resides. I keep a master and just copy it around to all the files when this occurs. Usually clears the error.
Seems like there must be a better way.
Thank you in advance. I appreciate any input and help I can get. Have a Great Day!!
Upvotes: 0
Views: 109
Reputation: 64487
ReSharper makes this trivial (almost to the point of being dangerous), it allows you to insert them with Alt+Enter and also highlights unused ones. VS also comes with basic support via right-click. Basically, I've never felt the need for the feature you describe - which doesn't exist so far as I'm aware.
I tend to sort mine alphabetically in two categories: .NET's System
namespaces first, everything else second. A third category could also separate internal from external namespaces, but this tends to be a little overkill for most situations.
However, take the following approach: if you really have that many using
statements, the contents of that code file (assuming you do using declarations outside of namespace declarations) might be Doing Too MuchTM. If your types are well targeted with as few responsibilities as you can get away with (read: aim for one), then you won't have many using statements anyway.
This naive code-smell alert mostly works, but you will have the odd type that has a proliferation of using declarations, so don't treat it as some sort of catch-all.
Upvotes: 4