bodong1987 / Avalonia.PropertyGrid

A property edit control in Avalonia like DevExpress's PropertyGridControl.
https://www.cnblogs.com/bodong
MIT License
169 stars 18 forks source link

Support for TypeDescriptionProvider #10

Closed furesoft closed 1 year ago

furesoft commented 1 year ago

Add support for TypeDescriptionProvider for encapsulation and make the classes that uses a custom typedescriptor smaller.

bodong1987 commented 1 year ago
private PropertyDescriptorCollection GetProperties(object target)
{
    if(target is ICustomTypeDescriptor ctd)
    {
        return ctd.GetProperties();
    }

    return TypeDescriptor.GetProperties(target);
}

The TypeDescriptor.GetProperties method is used internally to get properties, so TypeDescriptionProvider is natively supported. I have added a TypeDescriptionProvider use case in the latest version of the CustomObject example for reference.

image

public class TestCustomObject
{
    public string First { get; set; } = "";

    public string Second { get; set; } = "";

    [Browsable(false)]
    public string[] StringArray { get; set; } = new string[3] { "ABC", "DEF", "HJK" };
}