Set the attribute values of the String type in the object type to String. Empty and stringstring. empty.

Source: Internet
Author: User

Set the attribute values of the String type in the object type to String. Empty and stringstring. empty.

1 /// <summary> 2 /// set the attribute value of the String type to String. empty 3 // </summary> 4 // <typeparam name = "T"> strongly typed Entity </typeparam> 5 // <param name = "result"> </param> 6 public static void DefaultStringProperty <T> (T result) where T: class 7 {8 Type t = typeof (T); 9 System. reflection. propertyInfo [] propertyInfos = t. getProperties (); 10 foreach (PropertyInfo pi in propertyInfos) 11 {12 if (pi. propertyType. equals (typeof (string) 13 {14 object _ origanlValue = pi. getValue (result, null); 15 if (_ origanlValue = null) 16 {17 pi. setValue (result, string. empty, null); 18} 19} 20} 21}

 

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.