Not my idea, but it amused me. Thanks Dave.
namespace ExtensionMethodsAreEvil { class ExtensionMethodsAreEvil { public static void Main() { string myNullString = null; Console.WriteLine("Is the string empty? " + myNullString.IsNullOrEmpty()); } } public static class ExtendString { public static bool IsNullOrEmpty(this string s) { return string.IsNullOrEmpty(s); } } }
May 15, 2008 at 3:13 pm |
I’m missing the point, sorry Dave
!
I would also add that it is a very border line usage in my opinion, because it’s changing an important behaviour of the framework, that is throwing exceptions when calling a method on a null object.
When you start changing basic behaviours such as these, god knows where you’ll end up
May 15, 2008 at 3:45 pm |
Sorry I should have put “interesting”; i.e., horrible! This is completely wrong, wrong, wrong. But it works as comedy, I think.
May 15, 2008 at 3:52 pm |
Fair enough in that case
January 9, 2009 at 1:49 pm |
No, what’s evil is the VB extension methods, because you can pass the this pointer as a ref parameter. Now *thats* evil.