Before I go ahead and publish my next article, I have two minor gripes about Extension Method Syntax. Suppose I have a simple extension method:
{
}
I don't care much for explicity use of "this", sice this is basic OO:
I also don't care much for the following being invalid syntax:
That one informs me that type "Object" does not contain the FriendlyClassName() method, it would appear that the "this" keyword triggers the syntactical sugar of the extension method paths of the compiler?
Take a look at the next one, which Dan thinks is wonderful. Using this extension method:
public static bool IsNullOrEmpty(this System.Collections.ICollection collection)
if (null == collection || 0 == collection.Count)
{ return true; }
return false;
The following code does not throw any exceptions:
List<string> nullList = null;
if (nullList.IsNullOrEmpty())
//Whiskey Tango Foxtrot?
In a disgusting way, we could use a set of Extension Methods to impliment the NullObject pattern. IF it makes sense in your program, IF doing the usual coding for nulls isn't appropriate, IF the classical Null Object pattern isn't appropirate, IF Nullable<T> isn't appropriate for your scenario. That's a lot of ifs. Still, I found this to be useful in certain cases.
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Damon Payne
E-mail