Check whether the object is NULL or Empty, and check the object nullempty
Whether in Winform development or asp.net development, when you get data from a data source, you always don't know the status of the data. At this time, you always have to make a judgment on her, but every time I make a judgment, I always need to write a bunch of code,
After a long time, I always felt bad, so I had the following code encapsulation. This is an extended generic method written in System. in the namespace, it saves the time to repeatedly write so many codes. Each time you call the following command at the origin.
Haha,
1 namespace System 2 {3 public static class CheckValueExten 4 {5 // <summary> 6 // check whether the current object is NULL, or the string is NULLOrEmpty 7 // </summary> 8 // <typeparam name = "T"> </typeparam> 9 // <param name = "str"> </param> 10 // <returns> </returns> 11 public static bool CheckValue <T> (this T str) 12 {13 if (str is string) 14 {15 if (! String. isNullOrEmpty (str. toString () 16 {17 return true; 18} 19 else20 {21 return false; 22} 23} 24 else25 {26 if (str = null) 27 {28 return false; 29} 30 else31 {32 return true; 33} 34} 35} 36} 37} source code