zoukankan      html  css  js  c++  java
  • 通过反射获取类的所有属性和方法

     1    private void button1_Click(object sender, EventArgs e)
     2        {
     3            Type t = typeof(System.Drawing.Color);
     4            string className = t.Name;
     5            MessageBox.Show(className);
     6
     7            //获取所有方法
     8            System.Reflection.MethodInfo[] methods = t.GetMethods();
     9            this.textBox1.Text = "";
    10            foreach (System.Reflection.MethodInfo method in methods)
    11            {
    12                this.textBox1.Text += method.Name + System.Environment.NewLine;
    13            }

    14
    15            //获取所有成员
    16            System.Reflection.MemberInfo[] members = t.GetMembers();
    17
    18            //获取所有属性
    19            System.Reflection.PropertyInfo[] properties = t.GetProperties();
    20            foreach (System.Reflection.PropertyInfo property in properties)
    21            {
    22                this.lstColors.Items.Add(property.Name);
    23            }

    24        }

    25
    26        private void lstColors_SelectedIndexChanged(object sender, EventArgs e)
    27        {
    28           this.pictureBox1.BackColor=  System.Drawing.Color.FromName(((ListBox)sender).Text);
    29        }

    30
  • 相关阅读:
    Windows7,Ubuntu双系统,用MBR引导
    把Adblock Plus的过滤规则应用到IE9
    Linux shell学习
    vxworks下面网络连接调试的搭建
    uboot网卡成功识别
    uboot功能扩展篇
    uboot终于显示串口信息了
    uboot解决flash failed无限挂起的问题
    问题解决随笔
    琐事皆休,开始找工作~
  • 原文地址:https://www.cnblogs.com/saptechnique/p/1127834.html
Copyright © 2011-2022 走看看