方法属性动态设置问题 [BrowsableAttribute(var)]void Founction(var2){}怎样才能动态的实像[BrowsableAttribute(var)]中的var可以根据var2的值而不同。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void SetPropertyVisible(object target, string propertyName, bool visible) { PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(target); PropertyDescriptor property = pdc[propertyName]; if (property != null) { AttributeCollection ac = property.Attributes; Attribute attr = (BrowsableAttribute)ac[typeof(BrowsableAttribute)]; Type attrType = attr.GetType(); FieldInfo fld = attrType.GetField("browsable", BindingFlags.Instance | BindingFlags.NonPublic); fld.SetValue(attr, visible); } }不过你给方法设置Browsable属性干嘛呢?方法本来就不在PropertyGrid里显示。 求助:Scoket服务端程序导致整台服务器不能联网 使用GDI+绘制一条线段,当我把窗体最小化以后,然后再还原窗体,那个线段怎么就不见了,是怎么回事 求助:对各字节做"异或"运算是怎么回事? 请教一个简单问题:关于动态链接库的调用 最近学习C#感觉他就象浩瀚的海洋 烦请哪位把下列vb.net转换成c#代码? 我安装了.net为何不能执行aspx文件???? 求大神指教,拖动无边框窗体 C# 已经一个图片的网络地址 如何获取到图片上的内容 DataGrid中如何改写题头列字段的名字? 谁能帮我写段remoting接口的代码,关于验证用户名、密码的,不胜感激啊!!!! 用户控件如何隐藏事件
{
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(target);
PropertyDescriptor property = pdc[propertyName];
if (property != null)
{ AttributeCollection ac = property.Attributes; Attribute attr = (BrowsableAttribute)ac[typeof(BrowsableAttribute)]; Type attrType = attr.GetType();
FieldInfo fld = attrType.GetField("browsable", BindingFlags.Instance | BindingFlags.NonPublic);
fld.SetValue(attr, visible);
}
}不过你给方法设置Browsable属性干嘛呢?方法本来就不在PropertyGrid里显示。