Is PropertyDescriptor.IsBrowsable inconsistent with the associate Browsable() attribute?

StackOverflow https://stackoverflow.com/questions/17010098

  •  31-05-2022
  •  | 
  •  

Question

PropertyDescriptor is an abstract class from which custom property descriptors can inherit. The class has an IsBrowsable property, which, according to MSDN:

Gets a value indicating whether the member is browsable, as specified in the BrowsableAttribute. (Inherited from MemberDescriptor.)

My question is, how is this property related to the BrowsableAttribute in PropertyDescriptor.Attributes, for the associated property (defined e.g. by adding the [Browsable(false)] decorator to the property?

My confusion arises from the fact that I managed to replace the BrowsableAttribute with PropertyDescriptor.Attributes a new one, which was inconsistent with IsBrowsable.

Update Following Marc's answer, must I keep the BrowsableAttribute in sync with IsBrowsable? Are you aware of any controls which may look at one but not the other?

Was it helpful?

Solution

The default PropertyDescriptor implementation uses reflection and looks at the BrowsableAttribute. However, if you are providing your own PropertyDescriptor implementation then you are in charge - there are very few things that need to be followed. If your custom implementation uses an unrelated way to determine what is / is not browsable : that is up to your implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top