Hiding properties from the Property Grid
Taking a break from the main components, I decided to get around to writing a small configuration editor using .NET 2.0's lovely ability to edit .config files from code.
I have a custom Section Handler defined for my data, and decided the simplest thing to do would be to stick my custom ConfigurationElement objects onto a PropertyGrid and let the user edit the values directly.
The problem with that is that ConfigurationElement has several public properties that I inherit, and they show up in the grid:

My first instinct to hide them was to implement ICustomTypeDescriptor on my ConfigurationElement and implement GetProperties() so it only returns the properties I want. This turned out to be a ridiculously complicated endeavor, requiring me to implement many methods I don't care about just so I could get to GetProperties, which in turn required me to subclass the PropertyDescriptor class and override lots of properties that I didn't care about either. This whole design-time framework really needs an overhaul - it's way too complicated and the documentation is vague at best.
So I abandoned that approach and immediately set off on achieving my goal in the ugliest, hackiest way I could find. The easiest way to hide a property from the propertygrid is using the [Browsable(false)] attribute. Since the properties are unfortunately non-virtual, I had to hide them in order to override their attributes:
#region
Shadow unneeded properties.
[
Browsable(false)]
public new bool LockItem { get { return base.LockItem; } set { base.LockItem = value; } }
[
Browsable(false)]
public new ElementInformation ElementInformation { get { return base.ElementInformation; } }
[
Browsable(false)]
public new ConfigurationLockCollection LockAllAttributesExcept { get { return base.LockAllAttributesExcept; } }
[
Browsable(false)]
public new ConfigurationLockCollection LockAllElementsExcept { get { return base.LockAllElementsExcept; } }
[
Browsable(false)]
public new ConfigurationLockCollection LockAttributes { get { return base.LockAttributes; } }
[
Browsable(false)]
public new ConfigurationLockCollection LockElements { get { return base.LockElements; } }
#endregion
I simply hide them behind my new properties, and have those call the base's implementation in case they're actually used for anything.
Result? Works perfectly. Hardly clean, but it works: