C# 如何在WinForms集合编辑器中指定成员名称的源?

C# 如何在WinForms集合编辑器中指定成员名称的源?,c#,winforms,C#,Winforms,是否可以在下面的集合编辑器中更改用于源成员名称的属性 [TypeConverter(typeof(ExpandableObjectConverter))] [Serializable]//类也是bin序列化的 公共阶级社会政策 { /// ///社会政策的ID /// [说明(“社会政策ID”)] [显示名称(“ID”)、可浏览(真实)、类别(“一般”)] [XmlElement(“ID”)] 公共字符串ID{get;set;}=“POLICY_NULL”; /// ///可显示格式的社

是否可以在下面的集合编辑器中更改用于源成员名称的属性

[TypeConverter(typeof(ExpandableObjectConverter))]
[Serializable]//类也是bin序列化的
公共阶级社会政策
{
/// 
///社会政策的ID
/// 
[说明(“社会政策ID”)]
[显示名称(“ID”)、可浏览(真实)、类别(“一般”)]
[XmlElement(“ID”)]
公共字符串ID{get;set;}=“POLICY_NULL”;
/// 
///可显示格式的社会政策的名称
/// 
[可浏览(错误)]
[XmlIgnore]
公共字符串名称{get;set;}=“Null”;
/// 
///社会政策的树ID
/// 
[说明(“社会政策的树ID”)]
[显示名称(“TreeID”)、可浏览(真实)、类别(“一般”)]
[xmlement(“TreeID”)]
公共字符串TreeID{get;set;}=“POLICYTREE_NULL”;
...
}

目前,它的名称来源于默认名称,即在我的编辑器中始终为“Null”的name属性,但我宁愿它从ID中获取。我一直在搜索可以用来更改它的任何装饰,但没有找到任何装饰。

保存社会政策列表的类可以通过使用的自定义版本和覆盖GetDisplayText函数提供:

public class Test {

  [Editor(typeof(TestEditor), typeof(UITypeEditor))]
  public List<SocialPolicy> Policies { get; }

  public Test() {
    this.Policies = new List<SocialPolicy>();
    this.Policies.Add(new SocialPolicy());
  }

  public class TestEditor : CollectionEditor {
    public TestEditor(Type type)
        : base(type) {
    }

    protected override string GetDisplayText(object value) {
      if (value is SocialPolicy) {
        return ((SocialPolicy)value).ID;
      } else {
        return value.ToString();
      }
    }
  }
}
公共类测试{
[编辑器(typeof(TestEditor),typeof(UITypeEditor))]
公共列表策略{get;}
公开考试(){
this.Policies=new List();
this.Policies.Add(新社会政策());
}
公共类测试编辑器:CollectionEditor{
公共测试编辑器(类型)
:基本(类型){
}
受保护的覆盖字符串GetDisplayText(对象值){
if(价值是社会政策){
返回((社会政策)值).ID;
}否则{
返回值.ToString();
}
}
}
}
public class Test {

  [Editor(typeof(TestEditor), typeof(UITypeEditor))]
  public List<SocialPolicy> Policies { get; }

  public Test() {
    this.Policies = new List<SocialPolicy>();
    this.Policies.Add(new SocialPolicy());
  }

  public class TestEditor : CollectionEditor {
    public TestEditor(Type type)
        : base(type) {
    }

    protected override string GetDisplayText(object value) {
      if (value is SocialPolicy) {
        return ((SocialPolicy)value).ID;
      } else {
        return value.ToString();
      }
    }
  }
}