如果一个属性的类型是List类型,List的每一项又包含了子属性,那么可以通过标注ListPropertyAttribute,使得活字格设计器可以通过弹出二级对话框来编辑该属性。
注意,ObjType属性里声明的类型必须与属性类型一致。
自定义对象的类型应该从 ObjectPropertyBase 类派生,以确保在单元格复制的时候,子属性可以被正确的深克隆(ObjectPropertyBase实现了默认的深克隆逻辑)。
public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync { [ListProperty] public List<MyObj> MyProperty { get; set; } public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext) { return new ExecuteResult(); } public override CommandScope GetCommandScope() { return CommandScope.ExecutableInServer; } } public class MyObj : ObjectPropertyBase { public string Name { get; set; } public string Description { get; set; } }
在设计器中效果如下:
列表项目的子属性也可以通过标注来控制属性编辑控件。
下面例子中,额外声明了两个属性分别使用公式编辑器和命令编辑器。具体标注的用法请参考之前的章节。
public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync { [ListProperty] public List<MyObj> MyProperty { get; set; } public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext) { return new ExecuteResult(); } public override CommandScope GetCommandScope() { return CommandScope.ExecutableInServer; } } public class MyObj : ObjectPropertyBase { public string Name { get; set; } [FormulaProperty] public object FormulaProperty { get; set; } [ComboProperty(ValueList = "选项1|选项2|选项3")] public string Type { get; set; } }
在设计器中效果如下:
如果需要更细致的控制,可以通过ListPropertyAttribute的其他属性来控制。
- 控制列表最大或最小元素个数。
- 设置ListPropertyAttribute 的 MaxCount 和 MinCount 属性。
代码:
public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync { [ListProperty(MaxCount = 5, MinCount = 1)] public List<MyObj> MyProperty { get; set; } public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext) { return new ExecuteResult(); } public override CommandScope GetCommandScope() { return CommandScope.ExecutableInServer; } } public class MyObj : ObjectPropertyBase { public string Name { get; set; } public string Description { get; set; } }