我解决了我的问题。
我在这个论坛上写下这个。我认为这可能对其他人有帮助。A
以下是我的解决方案:
所以,我想创建自己的集合编辑器,就像域类中的一个属性(例如 NameTypeList)
我创建了自定义类,女巫有两个字段(字符串_name,字符串_type),并为这些字段设置了getter和setter。这是 NameType 类。我们可以在下面看到这个类的代码(下面是这个类的代码):
[Serializable]
public class NameType
{
public NameType()
{
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private string _type;
public string Type
{
get { return _type; }
set { _type = value; }
}
}
该类位于 Dsl 项目的主命名空间中。
接下来,我们将使用 System.ComponentModel.Design.CollectionEditor 类,因此我们需要将引用 System.Design 添加到我们的 Dsl 和 DslPackage 项目中。
因此,我们可以在域类中为我们的属性创建自定义编辑器。我们必须在我们的 Dsl 项目的自定义代码部分中创建编辑器类。我们可以使用下面的代码来做到这一点:
public class NameTypeEditor : System.ComponentModel.Design.CollectionEditor
{
public NameTypeEditor(Type t)
: base(t)
{
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
{
return base.EditValue(context, provider, value);
}
}
现在,我们应该在 Dsl 项目中添加我们的自定义类型。我们可以通过在树根的 DSL Explorer 中单击鼠标左键并选择“添加新外部类型”来做到这一点。
接下来,我们必须将 Name 填写为“List”,将 Namespace 填写为“System.Collections.Generic”。因此,我们将新类型作为自定义类 NameType 的对象的通用列表。
之后,我们只需要在我们的 DomainClass 中定义新的属性(例如,在 DslDefinition Designer 中,通过在 Domain Class 上单击鼠标右键并选择 Add->DomainProperty)
在 Properties 中,我们必须将 Name 定义为例如 NameTypeList,选择 Type 作为 List,选择 Kind 作为 CustomStorage 并设置自定义属性,例如 System.ComponentModel.Editor {typeof(NameTypeEditor), typeof(System.Drawing.Design.UITypeEditor)}
最后,我们必须为我们在 DomainClass 中选择的属性 NameTypeList 定义 CustomStorage 的方法。
我们可以通过创建此域类的部分类并编写 GetNameTypeListValue 和 SetNameTypeListValue 方法来做到这一点。
public partial class ClassElement
{
List<NameType> _nameTypeListClassParams = new List<NameType>();
public List<NameType> GetNameTypeListValue()
{
return _nameTypeListClassParams;
}
public void SetNameTypeListValue(List<NameType> value)
{
if (value != null)
_nameTypeListClassParams = value;
}
}
现在我们有了 Collection Property NameTypeList,我们可以轻松地编辑 NameType 值列表。
转换所有,构建并运行它。
我以这种方式解决了这个问题。我希望这个建议会对你有所帮助。