Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 942
Milan Gardian Avatar asked Jun 26 '09 20:06

Milan Gardian


People also ask

What name can you use for extension method sponsor class?

The class that defines such extension methods is referred to as the "sponsor" class, and it must be declared as static. To use extension methods, one must import the namespace defining the sponsor class.

How do you name an extension class?

Naming extension classes Preferably, the extension class should include the name of the type that is being extended. However, the name must also include a term, abbreviation, or prefix that distinguishes the class from other types.

How do you name a class extension in C#?

The naming convention would be StringExtensions for string, or simply the type name plus "Extensions".

How do you declare an extension method?

To define and call the extension methodDefine a static class to contain the extension method. The class must be visible to client code. For more information about accessibility rules, see Access Modifiers. Implement the extension method as a static method with at least the same visibility as the containing class.


1 Answers

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
like image 155
jrummell Avatar answered Oct 22 '22 04:10

jrummell