Skip to content

DescriptionAttribute and CategoryAttribute for Property Grid #107

@bepursuant

Description

@bepursuant

I've taken to throwing a property grid in some of my projects to easily edit configuration values. It's not the most flexible, but it works GREAT, and the way this library auto saves values means that selecting the config proxy in a property grid implements a full config UI with zero effort. Beautiful!

But I would love to add Descriptions and Categories to my config properties, so that they group together and I can provide notes about what the properties control.

I tried to attach a DescriptionAttribute from System.ComponentModel to the Config interface, but I believe it is being lost due to how attributes work, and also possibly due to how Castle is generating the proxy.

Is there a way to retain attributes, or to tell Castle to retain attributes from the interface definition?

Minimal example demonstrating a Description and Category attribute, and that they are not seen by the property grid when the config is the SelectedObject.

using Config.Net;
using System.ComponentModel;
using System.Windows.Forms;

namespace ConfigProperties
{
    public interface ITestConfig
    {
        [DefaultValue("A Property Value!"), 
         Description("A highly configurable item!"),
         Category("Main Category")]
        string SomeProperty { get; set; }
    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            // config proxy
            ITestConfig cfg = new ConfigurationBuilder<ITestConfig>().Build();

            // property grid
            PropertyGrid propertyGrid1 = new PropertyGrid
            {
                Dock = DockStyle.Fill,
                Location = new System.Drawing.Point(0, 0),
                SelectedObject = cfg
            };

            // window
            AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new System.Drawing.Size(350, 200);
            Controls.Add(propertyGrid1);
            Text = "ConfigProperties";
        }
    }
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions