'Naming conventions for extension method namespaces and sponsor classes
What naming conventions are you using for namespaces and sponsor classes? (i.e. the classes that hold extension method definitions)
Is there a standard/recommended .NET Framework naming convention? (the "Framework Design Guidelines, 2nd Edition" book only gives guidance on what namespaces not to use).
Solution 1:[1]
I haven't seen any official recommendations, but I've been organizing my extension classes like [NameSpace].[ClassName]Extensions:
ProjectName.Web.Util.ControlExtensions
ProjectName.Data.Util.CollectionExtensions
Solution 2:[2]
For the file name and class name us the Extensions suffix. Example, if you want to create an extension method for the name Foo call it FooExtensions and place it in a file name called FooExtensions.cs.
If you have many extension classes place them into a Extensions directory.
I've seen Microsoft use the same namespace as the class they wish to extend. This way they're readily available and easily discoverable without having to import them into scope by through using statements.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jrummell |
| Solution 2 | Fred |
