Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com
I've wrote  IsNullOrDefault generic helper function
 
    public  static bool IsNullOrDefault<T>(this Nullable<T> param) where T : struct
    {
        T deflt = default(T);
        if (!param.HasValue)
            return true;
        else if (param.Value.Equals(deflt))
            return true;
        return false;
    }
, but then realized that there is more short implementation on stackoverflow submitted by Josh
public static bool IsNullOrDefault<T>(this Nullable<T> value) where T : struct 
{ 
   
return default(T).Equals( value.GetValueOrDefault() ); 
} 
 
public static bool IsValue<T>(this Nullable<T> value, T valueToCheck) where T : struct 
{ 
   
return valueToCheck.Equals((value ?? valueToCheck)); 
} 

 
Posted on Friday, June 11, 2010 6:42 PM .Net Framework | Back to top


Comments on this post: IsNullOrDefault generic helper function for nullable types

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net