Appearance
命令属性
此特性为活字格V9.0.100.0新增功能
如果属性表示运行时执行的命令,希望通过命令对话框编辑,可以通过标注CustomCommandObjectAttribute 的方式设置。
注意,标注CustomCommandObjectAttribute的属性类型必须是 object
csharp
using GrapeCity.Forguncy.Commands;
using System.ComponentModel;
using System.Threading.Tasks;
namespace MyPlugin
{
public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
{
[CustomCommandObject]
[DisplayName("自定义子命令")]
public object CustomSubCommand { get; set; }
public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
{
await dataContext.ExecuteCustomCommandObjectAsync(this.CustomSubCommand, null);
return new ExecuteResult();
}
public override CommandScope GetCommandScope()
{
return CommandScope.ExecutableInServer;
}
}
}在设计器中效果如下

执行效果
如果需要更细致的控制,可以通过CustomCommandObjectAttribute的其他属性来控制
- 支持上下文参数
- 设置CustomCommandObjectAttribute 的 InitParamValues 和 InitParamProperties 属性
- 代码
csharp
public class MyPluginCellType : CellType
{
[CustomCommandObject(InitParamProperties = "x|y", InitParamValues = "X坐标|Y坐标")]
[DisplayName("双击命令")]
public object DoubleClickCommand { get; set; }
}3. 设计器效果
4. C# 添加上下文参数处理
javascript
public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
{
[CustomCommandObject(InitParamProperties = "x|y", InitParamValues = "X坐标|Y坐标")]
[DisplayName("自定义子命令")]
public object CustomSubCommand { get; set; }
public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
{
var param = new Dictionary<string, object>
{
{"X坐标",1 },
{"Y坐标",2 }
};
await dataContext.ExecuteCustomCommandObjectAsync(this.CustomSubCommand, param, "自定义子命令");
return new ExecuteResult();
}
public override CommandScope GetCommandScope()
{
return CommandScope.ExecutableInServer;
}
}5. 执行效果
2. 上下文参数支持添加描述, 1. 设置CustomCommandObjectAttribute 的 ParameterDescriptions 属性 2. 代码
csharp
public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
{
[CustomCommandObject(InitParamProperties = "x|y", InitParamValues = "X坐标|Y坐标",
ParameterDescriptions = "x:从坐标圆点水平向右的距离,单位为像素|y:从坐标原点垂直向下的距离,单位为像素")]
[DisplayName("自定义子命令")]
public object CustomSubCommand { get; set; }
public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
{
var param = new Dictionary<string, object>
{
{"X坐标",1 },
{"Y坐标",2 }
};
await dataContext.ExecuteCustomCommandObjectAsync(this.CustomSubCommand, param, "自定义子命令");
return new ExecuteResult();
}
public override CommandScope GetCommandScope()
{
return CommandScope.ExecutableInServer;
}
}3. 设计器效果
4. 说明 1. 添加适当的描述可以帮助用户更好的理解上下文变量的意义 2. 可以只给部分上下文变量添加注释
此属性需要活字格版本号大于9.0.100.0
更新: 2023-11-02 09:49:00
原文: https://www.yuque.com/robert-bh51n/ea8l6c/vh0lo1dgc629zdvh