Monday, January 30, 2012

Best Extension Methods: Get Core Type

Below extension method check for a type and Return underlying type if type is Nullable otherwise return the type
 /// 
    /// Return underlying type if type is Nullable otherwise return the type
    /// 
    public static Type GetCoreType(Type t)
    {
        if (t != null && IsNullable(t))
        {
            if (!t.IsValueType)
            {
                return t;
            }
            else
            {
                return Nullable.GetUnderlyingType(t);
            }
        }
        else
        {
            return t;
        }
    }

Compiled By: Rajesh Rolen

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates