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:          }

  • 相关阅读:
    Springboot使用PlatformTransactionManager接口的事务处理
    js 正则替换html标签
    【转】mysql查询时,查询结果按where in数组排序
    js输出字幕数字a-zA-Z0-9
    tcpdump使用教程
    rsync安装使用教程
    vim配置修改教程
    XD刷机报错bad CRC
    使用docker搭建seafile服务器
    案例:使用sqlplus登录报ORA-12547错误
  • 原文地址:https://www.cnblogs.com/jackping/p/2944275.html
Copyright © 2011-2022 走看看