Change Runtime View Attribute (C #)

I am trying to change the attribute of a Browsable variable in one of my classes at runtime. The class containing the attribute is as follows:

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 the value to false for SheathingType because I do not want this attribute to appear in the first form of my application. However, I want this to be 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);
        }

DisplayWallType , Browsable true. - , . DisplayWallType, , , SheathingType PropertiesGrid .

enter image description here

SheathingType - , - , ,

+4
1

Browsable , , TypeDescriptor. GetField("browsable") FieldInfo true. , - , false - .

TypeDescriptor , https://www.codeproject.com/articles/7852/propertygrid-utilities.

0

All Articles