【发布时间】:2014-08-15 16:48:15
【问题描述】:
是否有任何示例说明如何在 Windows Workflow Foundation 4.5 工作流中创建声明性约束?我查看了samples on MSDN,样本中没有任何声明性约束的示例。
【问题讨论】:
标签: constraints workflow-foundation
是否有任何示例说明如何在 Windows Workflow Foundation 4.5 工作流中创建声明性约束?我查看了samples on MSDN,样本中没有任何声明性约束的示例。
【问题讨论】:
标签: constraints workflow-foundation
Creating a Constraint Library is not that hard: 看下面的复制代码:
public static class CustomRulesLibrary
{
public static ValidationSettings Settings = new ValidationSettings()
{
AdditionalConstraints =
{
{typeof (Activity), new List<Constraint> {MustBeSomething()}},
}
};
public static Constraint MustBeSomething()
{
var element = new DelegateInArgument<Activity>();
return new Constraint<Activity>
{
Body = new ActivityAction<Activity, ValidationContext>
{
Argument1 = element,
Handler = new AssertValidation
{
IsWarning = true,
Assertion = new InArgument<bool>(env => (element.Get(env).DisplayName.Length > 2)),
Message = new InArgument<string>("Some custom message"),
}
}
};
}
}
希望以上有所帮助。
【讨论】: