Extension methods, separate class, or both

Extend, separate, or both

  • Extension methods

  • Separate class-only

  • Separate class, but optionally extension methods through an intermediate namespace


Results are only viewable after voting.

mrjminer

Platinum Member
Dec 2, 2005
2,739
16
76
Preference question.

Have some methods that could be made into extension methods, but there are about 20 of them. The class they'd go on is already pretty well populated.

Would you use them as extension methods, leave them in a separate class, or do both via an intermediate namespace that adds extension methods which just reference the separate class?
 
Last edited:

Train

Lifer
Jun 22, 2000
13,579
75
91
www.bing.com
Depends, are they all extensions on the same thing?

It seems the convention is to group them logically on what they extend. My team keeps all string extensions in one class, all DateTime extensions in one.

As for numerics, it varies depending on how many there are. One extension for each numeric type? Keep them all in one class. Lots of extensions for each numeric type? Separate them to int,float,long, etc classes
 

mrjminer

Platinum Member
Dec 2, 2005
2,739
16
76
Depends, are they all extensions on the same thing?

It seems the convention is to group them logically on what they extend. My team keeps all string extensions in one class, all DateTime extensions in one.

As for numerics, it varies depending on how many there are. One extension for each numeric type? Keep them all in one class. Lots of extensions for each numeric type? Separate them to int,float,long, etc classes

I do the same thing, as well.

It's a single class, but the class I could extend probably has about 35 existing methods. Currently, I have about 20 methods that I could easily just switch over to extension methods for the class, but more will probably be added in the future. This is still well within a manageable amount for me for extension methods

I'm just wondering what most would do with classes that already have a fair amount of methods on them (that's why I left the actual count for mine out of the original post since it will vary by person).

IE: at some point do you find you have excessive amount of extension methods clogging up your IntelliSense and then opt to just leave them in a separate class. I explained this poorly in the OP :D
 
Last edited:

Train

Lifer
Jun 22, 2000
13,579
75
91
www.bing.com
OK I think I understand you question better now.

Ours is already in a separate namespace so typically what happens is you only include it when you come across a need for it. Something like MyProjectName.Tools.Extensions

But ya, with a lot of them, especially on the string class, sometimes the methods that are typically used for large strings (like a several paragraph long forum post) don't make sense for small text variables like FirstName, and vice versa, or some methods that are meant for parsing lists of ints, so it does get the "clutter" effect. But so far it hasn't been such a problem that we felt the need to split them into separate namespaces.

Once you know your codebase, the core framework, and extensions well enough, intellisense should really only exist to help you type faster. Rarely do I find myself scrolling up and down the intellisense window looking for a method to use. Instead I type the first 2 or 3 letters and hit tab.
 

mrjminer

Platinum Member
Dec 2, 2005
2,739
16
76
OK I think I understand you question better now.

Ours is already in a separate namespace so typically what happens is you only include it when you come across a need for it. Something like MyProjectName.Tools.Extensions

But ya, with a lot of them, especially on the string class, sometimes the methods that are typically used for large strings (like a several paragraph long forum post) don't make sense for small text variables like FirstName, and vice versa, or some methods that are meant for parsing lists of ints, so it does get the "clutter" effect. But so far it hasn't been such a problem that we felt the need to split them into separate namespaces.

Once you know your codebase, the core framework, and extensions well enough, intellisense should really only exist to help you type faster. Rarely do I find myself scrolling up and down the intellisense window looking for a method to use. Instead I type the first 2 or 3 letters and hit tab.

Yea that's what I mean

I should have put this poll in a range of methods, like 0-50, 51-100, etc. I was apparently unknowingly drunk when I created the thread or something