[英]How do I add a constraint to a declarative workflow in WF 4.5?
創建約束庫並不難:請看下面的復制代碼:
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"),
}
}
};
}
}
希望以上有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.