Stephen Walsh
1 min readJul 3, 2022

--

Thanks for thinking about this Andre!

For me extension methods are about adding functionality to code that you don't own. Otherwise you'd just add the functionality in the base code itself.

What grinds me gears about the startup method from Microsoft seems like they are happy to new up a class and then throw it away after a single use. There's no bigger purpose for this class than to execute two methods. So I figure extend the types rather than build something new.

It's rather stylistic more than anything else but I find it helpful.

According to the docs on Extension Methods, Microsoft advocate for the a new class, if I'm reading it right but also say that extensions are good for code you don't control.

While it's still considered preferable to add functionality by modifying an object's code or deriving a new type whenever it's reasonable and possible to do so, extension methods have become a crucial option for creating reusable functionality throughout the .NET ecosystem. For those occasions when the original source isn't under your control, when a derived object is inappropriate or impossible, or when the functionality shouldn't be exposed beyond its applicable scope, Extension methods are an excellent choice.

Either way happy to disagree on this one, I do like my way better :)

--

--

Stephen Walsh
Stephen Walsh

Written by Stephen Walsh

Hello! I’m a Husband, Father, Software Engineer, Learner & Leader. I live in Wisconsin, and spend my days trying to balance all of the above.

No responses yet