我想這樣做:屬性和功能的構造
[AttributeUsage(AttributeTargets.Property,
Inherited = false,
AllowMultiple = true)]
sealed class MyAttribute : Attribute
{
readonly string showName;
readonly Type controlType;
public Type ControlType
{
get { return controlType; }
}
readonly Func<Control, object> selector;
public Func<Control, object> Selector
{
get { return selector; }
}
public MyAttribute(string showName,
Type controlType,
Func<Control, object> selector)
{
this.showName = showName;
this.controlType = controlType;
this.selector = selector;
}
public string ShowName
{
get { return showName; }
}
}
class Foo
{
// problem. Do you have an idea?
[My("id number",
typeof(NumericUpDown),
Convert.ToInt32(control=>((NumericUpDown)control).Value))]
public int Id { get; set; }
}
我想爲起飛做屬性包含名稱,類型控制,並選擇從控制屬性的值。
我嘗試做,不能。
你重新發明的PropertyGrid。不利用它的所有管道(TypeConverter,UITypeEditor)將是一個錯誤。要做的最好的事情就是提前思考,並問問自己如何爲這些屬性創建功能編輯器。控制位置和大小等細節非常重要。 – 2012-01-07 22:34:45