>>>Probably true - but an extension method gets round Dmitry's naming problem :-}
>>
>>
>>True - but will clutter up
>>
>How do you decide when to go with a new class and when to go with extension and does extension bring overhead comparing with the class?
> How do you decide when to go with a new class and when to go with extension
Personal taste
If it does a specific thing, I prefer a new class - probably with static methods
If not often used- I prefer a separate class
eg I have one called BitOperations. It can test, set, clear a bit. It can rotate
If it can be used by more than one type, and I find it useful, I go for extension methods
For example, I have extension methods that test for equality. Can be used with any type that Implements IEquatable< T >
eg: testing whether ranges of arrays contain the same
> does extension bring overhead comparing with the class?
I don't think so. An extension method can also be called in the 'normal' way
static class Test
{
internal static void Go()
{
int one = 1, two = 2;
bool b = one.IsEqual(two);
bool x = Equality.IsEqual(one, two); // same as above
}
}
static class Equality
{
internal static bool IsEqual<T>(this T one, T two) where T : IEquatable<T>
{
return one.Equals(two);
}
}
Gregory