Search code examples
propertygridnetcoreapp3.1

Propertygrid in netcoreapp


I used to be able to do this in Net472, but run into an error when I tried to do the same in Netcoreapp3.1

enter code here
        BrowsableAttribute theDescriptorBrowsableAttribute = (BrowsableAttribute)theDescriptor.Attributes[typeof(BrowsableAttribute)];
        FieldInfo browsablility = theDescriptorBrowsableAttribute.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance);

        // Set the Descriptor's "Browsable" Attribute
        browsablility.SetValue(theDescriptorBrowsableAttribute, isBrowsable);

browsablility returns null. it seems it is now a OnInitOnly and cannot be set.

Any idea? I just want to make the item visible or invisible based on attributes.


Solution

  • I finally resolve the problem by creating a custom attribute and set that attribute to true or false. and assign that custom attribute to propertgird.BrowsableAttribute