ExtensionMethod.NET Home of 874 C#, Visual Basic, F# and Javascript extension methods

IsNullOrDBNull

We all know that objects can be null, but when dealing with databases, a new null type shows up, the DBNull. This extention method detects it along with the null.

Source

public static bool IsNullOrDBNull(this object obj)
{
    if (obj == null || obj.GetType() == typeof(DBNull))
        return true;
    else
        return false;
}

Example

Object obj = null;
bool b = obj.IsNullOrDBNull();

Author: Hadi Lababidi

Submitted on: 19 feb 2010

Language: C#

Type: System.Object

Views: 5894