.NET动态绑定特性(实现PropertyGrid动态设置)

 

.NET动态绑定特性(实现PropertyGrid动态设置)

 

代码:

 ///动态修改特性       PropertyDescriptorCollection dataAttributes = TypeDescriptor.GetProperties(data);

 Type displayType = typeof(BrowsableAttribute);

 var fieldInfo = displayType.GetField("browsable", BindingFlags.NonPublic | BindingFlags.Instance);

 fieldInfo.SetValue(dataAttributes["Color"].Attributes[displayType], true);

需要注意的是,这里修改的是特性BrowsableAttribute 私有字段browsable,由于自动属性Browsable并没有set方法,只好如此了,如果有更好的方法,希望大神指导!

相关文章:

  • 2021-12-28
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-05
  • 2021-09-18
猜你喜欢
  • 2021-07-28
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
相关资源
相似解决方案