Use reflection to get static property values for static classes (string representations of known property names)

Source: Internet
Author: User

Columns such as getting the value of the phone property

typeof (Excelcolumnname). GetProperty ("Phone"). GetValue (nullnull)//Excelcolumnname is a static class

The Excelcolumnname class is as follows:

1 /// <summary>2         ///columns that are included in Excel to upload3         /// </summary>4          Public Static classExcelcolumnname5         {6              Public Static stringPhone {Get;Set; } ="mobile Number (required)";7              Public Static stringName {Get;Set; } ="User name (the default is the same as the phone number)";8              Public Static stringRealname {Get;Set; } ="real name";9              Public Static stringCardno {Get;Set; } ="ID Number";Ten              Public Static stringReferees {Get;Set; } ="Recommended Person"; One              Public Static stringCreatetime {Get;Set; } ="Registration Date (format 2016/1/2)"; A              Public Static stringCompanyName {Get;Set; } ="Work Unit"; -              Public Static stringEmail {Get;Set; } ="Email"; -  the              Public Staticlist<string> columnlist =Newlist<string> -             { - Phone, - Name, + Realname, - Cardno, + Referees, A Createtime, at CompanyName, - Email -             }; -}

Ps: It is important to note that static fields are not available if they are defined as follows: In this case, the phone is not considered to be a property of the class, and it cannot be reached by the reflection property.

 Public Static string " mobile Number (required) ";

  

Use reflection to get static property values for static classes (string representations of known property names)

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.