zoukankan      html  css  js  c++  java
  • 在设计时通过反射改变属性的特性

       1: public class A

       2:      {
       3:          public string Name { get; set; }
       4:   
       5:          public string Age { get; set; }
       6:   
       7:          public bool IsOk { get; set; }
       8:   
       9:          [Browsable(false)]
      10:          public bool Visiable { get; set; }
      11:      }
      12:   
      13:  private void button1_Click(object sender, EventArgs e)
      14:          {
      15:              A a = new A();
      16:              Type type = typeof(BrowsableAttribute);
      17:   
      18:              PropertyDescriptorCollection props = TypeDescriptor.GetProperties(a);
      19:              AttributeCollection attrs = props["Visiable"].Attributes;
      20:   
      21:              FieldInfo fld = type.GetField("browsable", BindingFlags.Instance | BindingFlags.NonPublic);
      22:              fld.SetValue(attrs[type], true);
      23:   
      24:              this.propertyGrid1.SelectedObject = a;
      25:          }

  • 相关阅读:
    开启进程
    操作系统
    多线程(进程)目录
    网络编程-基于UDP协议套接字
    网络编程-文件传输
    EXt js 学习笔记总结
    Sencha Toucha 2.1 文件上传
    Sencha Touch 2.1学习图表Chart概述
    Sencha Touch 2.1 Chart属性中文解释
    Ext.Ajax.request方法 参数
  • 原文地址:https://www.cnblogs.com/jackping/p/2944275.html
Copyright © 2011-2022 走看看