使用系统命名空间类库:好还是坏类库、系统、空间

2023-09-03 21:14:53 作者:奶气缠身*>c<*

是不是在我的类库使用系统命名空间是个好主意?

Is it a good idea to use "system namespaces" in my class libraries?

示例:

namespace System.Web {
    public static class RequestExtensions {
        public static bool IsPost(this HttpRequest r) {
            return string.Compare(r.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) == 0;
        }
    }
}

的优点:无须包括其他用途的从句(尤其是扩展方法),因此所有添加引用到库后直接可用

The advantage: no need to include additional uses-clauses (especially for extension methods), so all becomes available straight after adding reference to the library.

最好的样本 NUnitEx 项目(使用NUnit的命名空间)。

The best sample is NUnitEx project (which uses NUnit's namespace).

缺点:潜在的名称冲突

推荐答案

我有第二个其他人谁说,它的一个坏的想法。命名空间是一个组织的工具,在许多层面上。他们不仅允许你重用标识符为自己的目的,而无需与其他公司发生冲突,它们还允许不同的公司从您的或任何其他人的孤立他们的产品。把code到系统命名空间可以非常混乱谁使用你的类型的人。

I have to second everyone else who says its a BAD idea. Namespaces are an organizational tool, on many levels. Not only do they allow you to reuse identifiers for your own purposes without conflicting with other companies, they also allow different companies to isolate their product from your's or anyone else's. Putting code into the System namespace can be very confusing for the people who use your types.

此外,人们知道,在一个系统命名空间什么是良好的,坚实,经过测试,社区审核,详细记录的$ C $的是来自微软℃。多数民众赞成在多种因素的pretty的一系列重要,不辜负......通过坚持你的code在同一个命名空间,不但你是否认为你code是很好的,但你必须辜负吧。

Additionally, people know that anything in a System namespace is good, solid, tested, community vetted, thoroughly documented code that came from Microsoft. Thats a pretty important set of factors to live up to...by sticking your code in the same namespace, not only are you claiming your code is that good, but you have to live up to it.

 
精彩推荐
图片推荐