do you use extension methods intensively in your projects?
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
I use them. I dunno about "extensively". Let's say they are pretty common.
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
For common tasks, and when it makes sense. Absolutely!
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
Very much so! Done properly, they make the code so much more compact and readable.
Cheers, Mick ------------------------------------------------ It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
As per Super Lloyd - I use them, I don't know about 'extensively', but, 'when it seems to make sense'
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
Seconding the others.
Wrong is evil and must be defeated. - Jeff Ello
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
I have an assembly full of them.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
Like all other language features, I use them when it's appropriate. That means sometimes I do, and sometimes I don't. It depends on what the method is doing and whether it makes more sense as an extension method or as a property / standard method. If you need to add functionality to a sealed class such as
String
then it makes a lot of sense. If the class is your own, then it's just silly to use extension methods ... :laugh:Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
As OG pointed out when adding functionality to sealed class then yes, but otherwise I consider between extension methods and inheritance. Mainly because I often need more functionality than just a method and perhaps even new instance variables. But yes I use them when I see fit.
-
As OG pointed out when adding functionality to sealed class then yes, but otherwise I consider between extension methods and inheritance. Mainly because I often need more functionality than just a method and perhaps even new instance variables. But yes I use them when I see fit.
I'm sure the OP means extension methods for native .Net objects, such as
string
,Type
,DateTime
, etc.".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
I use them a lot to encapsulate the business meaning of a specific IEnumerable Where clause. Makes code much more readable.
-
I'm sure the OP means extension methods for native .Net objects, such as
string
,Type
,DateTime
, etc.".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
I use them a lot to encapsulate the business meaning of a specific IEnumerable Where clause. Makes code much more readable.
My most recent ones calculate business chart trend line values from either an
IEnumerable<double>
or aIEnumerable<T>
using the named property.".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
Like all other language features, I use them when it's appropriate. That means sometimes I do, and sometimes I don't. It depends on what the method is doing and whether it makes more sense as an extension method or as a property / standard method. If you need to add functionality to a sealed class such as
String
then it makes a lot of sense. If the class is your own, then it's just silly to use extension methods ... :laugh:Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
OriginalGriff wrote:
If the class is your own, then it's just silly to use extension methods
No it's not! On a few occasions I've created an interface, ISomething, and before writing any implementation I wrote a few extension methods I knew I needed. And then I wrote the implementations (and got so much functionality out of the box!) :D Kind of like collections and LINQ, all M$ "own" classes, but they still have lots of extension methods.
Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability. — Edsger W. Dijkstra
Regards, Sander
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
Yes I do. I use the ones MS created, I use them to enhance built-in types and I use them to enhance my own types. Only when it makes sense, of course :D
Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability. — Edsger W. Dijkstra
Regards, Sander
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
public static bool Yes(this T foo) {return true;}
Marc
Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
-
just curious. recently I start to use extension methods in my projects.
diligent hands rule....
-
public static bool Yes(this T foo) {return true;}
Marc
Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Samhain (Halloween) is still fifteen days away, but you got my vote on this one, anyhow. cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
-
OriginalGriff wrote:
If the class is your own, then it's just silly to use extension methods
No it's not! On a few occasions I've created an interface, ISomething, and before writing any implementation I wrote a few extension methods I knew I needed. And then I wrote the implementations (and got so much functionality out of the box!) :D Kind of like collections and LINQ, all M$ "own" classes, but they still have lots of extension methods.
Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability. — Edsger W. Dijkstra
Regards, Sander
Hi Sandor, I'd really appreciate seeing an example of Extension Methods for an Interface. cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
-
Hi Sandor, I'd really appreciate seeing an example of Extension Methods for an Interface. cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
The entire LINQ library depends upon it. For example the
Count()
extension method on collections may look as follows:public static class Extensions
{
public static int Count(this IEnumerable collection)
{
int count = 0;
using (var enumerator = collection.GetEnumerator())
{
while (enumerator.MoveNext())
{
count += 1;
}
}
return count;
}
}The actual extension method checks for null and tries to cast to
ICollection<T>
andICollection
for theCount
property first, but it's an extension on an interface. There are LOTS of them...Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability. — Edsger W. Dijkstra
Regards, Sander