是否有任何关于如何在Windows Workflow Foundation 4.5工作流中创建声明性约束的示例?我查看了samples on MSDN,并且样本中没有任何声明性约束的例子。
答案 0 :(得分:-1)
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"),
}
}
};
}
}
希望以上有所帮助。