Using Linq to enhance (?) readibility

I am not certain if this is a valid example of a fluent interface, but I thought I would post it as I found it a reasonably interesting way to remove checks for != null or == null from code to make it "read" better. This example creates an extension method using Linq to extend reference objects.
 
public static class Utility {
     public static bool IsNotNull<T>(this T item) where T : class {
          return item != null;
     }
     public static bool IsNull<T>(this T item) where T : class {
          return item == null;
     }

 
You can, then, write checks to be like this for any reference object:
 
if(obj.IsNotNull())  {

    …
}
 
As I said, I am not certain if this is truly a "fluent interface", but can (arguably) make the code read easier.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s