I am trying to hide or show some properties of a property grid at runtime depending on certain conditions but don't seem to be winning. I have tried the below but the isBrowsable is returning null and hence I am unable to modify the browsable attribute.
var descriptor = TypeDescriptor.GetProperties(GetType())["MyPropertyName"];
var attrib = (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)];
var isBrowsable = attrib.GetType().GetField("browsable", BindingFlags.NonPublic | BindingFlags.Instance); //This is returning null
isBrowsable.SetValue(attrib, value);
How can I hide or show properties of the propertygrid at runtime in .net6?