. NET reflection User-Defined Enumeration type,. net reflection-defined Enumeration

Source: Internet
Author: User

. NET reflection User-Defined Enumeration type,. net reflection-defined Enumeration

Sample Code:

1 using System; 2 using System. collections. generic; 3 using System. componentModel; 4 using System. data; 5 using System. drawing; 6 using System. linq; 7 using System. text; 8 using System. threading. tasks; 9 using System. windows. forms; 10 11 namespace ReflectEnumDemo12 {13 //. NET supports symmetric (private key encryption) algorithm types 14 enum Encriptions15 {16 Aes, 17 DES, 18 RC2, 19 Rijndael, 20 TripleDES21} 22 23 public partial class MainForm: form24 {25 public MainForm () 26 {27 InitializeComponent (); 28 29 this. load + = (object sender, EventArgs e) => 30 {31 Type type = typeof (Encriptions); 32 var enumValues = type. getEnumValues (); // obtain all enumerated values 33 34 DataTable dataTable = new DataTable (); // table, to bind 35 dataTable to the UI. columns. addRange (new DataColumn [2] {new DataColumn ("Key", typeof (string), new DataColumn ("Value", typeof (int ))}); // define the table field 36 37 foreach (var item in enumValues) 38 {39 DataRow dataRow = dataTable. newRow (); // defines the row 40 dataRow ["Key"] = type. getEnumName (item); // The column Value is 41 dataRow ["Value"] = (int) item; 42 dataTable. rows. add (dataRow); // insert row 43} 44 45 // cboShow is a ComboxBox control 46 this. cboShow. dataSource = dataTable; // UI data source. The data source must be of the type that implements the IList interface. 47 this. cboShow. valueMember = "Value"; 48 this. cboShow. displayMember = "Key"; 49 }; 50} 51} 52}

Execution result diagram:

 

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.