Check whether the object is NULL or Empty, and check the object nullempty

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.