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

  • 相关阅读:
    Web API初印象
    SQL注入总结篇
    Debian Linux 下安装pip3
    DVWA:环境搭建
    AWVS使用手册
    常见的反爬虫和应对方法
    Fiddler抓取手机APP数据包
    爬虫 Scrapy框架 爬取图虫图片并下载
    python 爬虫基础知识(继续补充)
    Python 爬虫 多进程清洗代理
  • 原文地址:https://www.cnblogs.com/jackping/p/2944275.html
Copyright © 2011-2022 走看看