设置在运行时BrowsableAttribute的价值 [英] Setting value of BrowsableAttribute at runtime

查看:281
本文介绍了设置在运行时BrowsableAttribute的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设定 BrowsableAttribute 价值对一些 MyClass的在运行实例的属性:

I wanted to set a value of BrowsableAttribute for some of MyClass instance's properties at runtime:

 public class MyClass
{
     [Browsable(true)]
     public int P1 { get; set } 
     ...
}

请指教如何可以做到的,以及如何 BrowsableAttribute 添加到 MyClass的实例的属性在运行时如果这个属性不存在。

Please advise how it can be done as well as how to add BrowsableAttribute to a MyClass instance's property at runtime if this attribute doesn't exist.

推荐答案

您可以实现自定义类型说明符 - 它截获属性的道路上无论是使用它。因此,有效果,看起来像属性正在发生变化。

You can implement a custom type descriptor - which intercepts the the attribute on the way to whatever is using it. Thus having an effect which looks like the attribute is changing.

请参阅 - 第1部分,的第2部分

这篇关于设置在运行时BrowsableAttribute的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆