public static void SetPropertyVisibility(object obj, string propertyName, bool visible)
{
Type type = typeof(BrowsableAttribute);
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
if (null == props.Find(propertyName, false))
{
return;
}
AttributeCollection attrs = props[propertyName].Attributes;
FieldInfo fld = type.GetField("Browsable", BindingFlags.Public | BindingFlags.Instance);
if (null == fld)
{
return;
}
fld.SetValue(attrs[type], visible);
}
这个函数在.net4中是可以用的,但是.net6中用的话fld 得到的值为null,好像不支持了,那有其它方法吗。