你如何管理你的扩展方法的命名空间? [英] How do you manage the namespaces of your extension methods?

查看:206
本文介绍了你如何管理你的扩展方法的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您使用的是全球性的,包罗万象的命名空间为您的所有扩展方法,或者你放在同一个命名空间的扩展方法的类(ES)它们扩展?

Do you use a global, catchall namespace for all of your extension methods, or do you put the extension methods in the same namespace as the class(es) they extend?

还是你使用其他方法,比如一个应用程序或库特定的命名空间?

Or do you use some other method, like an application or library-specific namespace?

我问,因为我有一个需要延长 System.Security.Principal.IIdentity ,并把在 System.Security.Principal 命名空间似乎是有道理的,但我从来没有见过它这样做的方式。

I ask because I have a need to extend System.Security.Principal.IIdentity, and putting the extension method in the System.Security.Principal namespace seems to make sense, but I've never seen it done this way.

推荐答案

我会建议把所有的在一个单一命名空间扩展的方法(顺便说一句,这也是微软通过把他们在System.Linq的'命名空间内一个单一的类'扩展'使用LINQ一样)。

I would recommend putting all your extension methods in a single namespace (incidentally this is also what Microsoft did with Linq by putting them in a single class 'Extensions' inside the 'System.Linq' namespace).

由于Visual Studio提供任何线索,如何找到您要使用的扩展方法,它仅需要记住一个名称空间减少混乱。

Since Visual Studio provides no clues as to how to locate an extension method that you want to use, it reduces confusion by only having to remember one namespace.

这篇关于你如何管理你的扩展方法的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆