[BrowsableAttribute(var)]
void Founction(var2)
{
}怎样才能动态的实像[BrowsableAttribute(var)]中的var可以根据var2的值而不同。

解决方案 »

  1.   

            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里显示。