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中的图标(Sprites雪碧图、Icon Font字体图标)
    那些不推荐使用的html标签
    Vim学习
    web前端性能优化建议
    开发基础
    数据库事务
    java集合详解
    java基础总结大纲(一)
    java设计模式之单例模式(饿汉)
    java设计模式之单例模式(内部静态类)
  • 原文地址:https://www.cnblogs.com/jackping/p/2944275.html
Copyright © 2011-2022 走看看