November 12, 2009

Extending code readability by extension methods

Filed under: .net,programming Himanshu @ 9:40 am

If you haven’t noticed, note that extension methods can also be called on null objects. Meaning, there can be extension method which checks whether an object is null or not. So,

public void Operate(InputType inputObject)
{
    if (null != inputObject) 
    { 
        . . .
    }
} 

public void Operate(InputType inputObject)
{
    if (null == inputObject) 
    { 
        . . .
    }
} 
 

Can be replaced by

 
public void Operate(InputType inputObject)
{
    if (inputObject.IsNotNull()) 
    { 
        . . .
    }
} 

public void Operate(InputType inputObject)
{
    if (inputObject.IsNull()) 
    { 
        . . .
    }
} 

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress