I'm trying to change the Browsable attribute of a variable in one of my classes at runtime. The class containing the attribute looks like this:
public class DisplayWallType : WallType
{
[TypeConverter(typeof(SheathingOptionsConverter))]
[Browsable(false)]
public override Sheathing SheathingType { get; set; }
public DisplayWallType(string passedName, string passedType, bool passedMirrorable, Distance passedHeight, string passedStudPattern, Distance passedStudSpacing, VaporBarrier passedBarrier)
: base(passedName, passedType, passedMirrorable, passedHeight, passedStudPattern, passedStudSpacing, passedBarrier)
{
}
/// <summary>
/// Empty constructor for XML serialization
/// </summary>
public DisplayWallType()
{
}
}
I initially set it to false for SheathingType because I don't want that attribute to show up in the first form of my application. However, I do want it visible in my second form so I have this method to change it
private void _makeSheathingVisible(DisplayWallType wallTypeToMakeSheathingVisible)
{
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(wallTypeToMakeSheathingVisible.GetType())["SheathingType"];
BrowsableAttribute attrib = (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)];
FieldInfo isBrow = attrib.GetType().GetField("browsable", BindingFlags.NonPublic | BindingFlags.Instance);
isBrow.SetValue(attrib, true);
}
That method above takes a DisplayWallType object and ensures that Browsable is set to true. My second form is a treeview combined with a property grid. The treeview is populated with instances of DisplayWallType and when one is selected, it is passed into that method so that SheathingType shows up in the PropertiesGrid with the rest of the properties from the parent class.
However, SheathingType still does not show up as a property so something is wrong with my approach but I have no idea what