1.描述
为了确保命令类型插件的属性值是有效的,插件应该实现ICommandChecker接口。
2.添加命令类型插件检查器
下面的示例中使用了ICommandChecker:
[Designer("SendWeChatCommand.SendWeChatCommandDesigner,SendWeChatCommand")]
public class SendWeChatCommand : Command
{
public string ToPersonID
{
get; set;
}
[FormulaProperty(true)]
public object Content { get; set; }
}
public class SendWeChatCommandDesigner: CommandDesigner<SendWeChatCommand>, ICommandChecker
{
public IEnumerable<ForguncyErrorInfo> CheckCommandErrors(IBuilderCommandContext context)
{
if (string.IsNullOrEmpty(this.Command.ToPersonID))
{
yield return new ForguncyErrorInfo()
{
Message = "The person id can't be empty.",
ErrorType = ForguncyErrorType.Error
};
}
if (this.Command.Content == null || object.Equals(this.Command.Content, ""))
{
yield return new ForguncyErrorInfo()
{
Message = "The content can't be empty.",
ErrorType = ForguncyErrorType.Warning
};
}
}
}
重新构建工程并重启设计器,选择单元格设置为按钮类型,设置命令为刚创建的“SendWeChatCommand”,并设置内容为页面上的单元格,如下:
运行页面后检查错误如下:

