[英]Is there a better way to manage using namespace directives in the head of a file
I'm a complete newb. 我是新手。 I see that these using statements or references at the top of the page are a pain to manage.
我看到页面顶部的这些using语句或引用很难管理。 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
. 有时我会收到诸如
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!!
祝你有美好的一天!!
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. ReSharper使这个琐碎的事(几乎到危险的程度),允许您使用Alt + Enter插入它们,并突出显示未使用的内容。 VS also comes with basic support via right-click.
VS还通过右键单击提供基本支持。 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. 我倾向于按字母顺序将我的分类分为两类:.NET的
System
名称空间首先,其他所有内容。 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 Much TM . 但是,采用以下方法:如果您确实有那么多
using
语句,则该代码文件的内容(假设您确实使用名称空间声明之外的声明)可能是Doing Too Much TM 。 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. 如果您的类型具有很好的针对性,并且尽您所能避免的责任(请阅读:针对某一类),那么您将不会有太多的using语句。
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. 这种幼稚的代码气味警报通常可以正常工作,但是您将拥有使用声明的泛滥类型的奇数类型,因此请不要将其视为包罗万象的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.