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);
}

这个函数在.net framework中是可以用的,但是.net8中用的话fld 得到的值为null,好像不支持了,那有其它方法吗。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐