Peter17 Peter17 - 1 year ago 110
C# Question

How to group extension methods?

I have a static class with bunch of extension methods for various types. Is there any utility or the way to split it into several classes - separate class for the each target type.

Answer Source

Putting your various extension methods into different classes is a good idea from a "clean code" perspective, but the main "grouping" of extension methods happens by placing them into different namespaces. The reason is that extension methods are made available by "using" the appropriate namespace.

Putting different groups of extension methods into different namespaces is a good idea since you could have colliding extension methods. If that happens, and each logical group of extension methods is in a fine-grained namespace, you should be able to resolve the conflict by simply removing one of the using statements, thereby leaving the using statement that contains the extension method you actually want.

Here's a link to some best practices:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download