簡體   English   中英

如何在WF 4.5中向聲明性工作流添加約束?

[英]How do I add a constraint to a declarative workflow in WF 4.5?

是否有任何示例說明如何在Windows Workflow Foundation 4.5工作流中創建聲明性約束? 我已經在MSDN上查看了示例 ,並且示例中的任何地方都沒有聲明約束的示例。

創建約束庫並不難:請看下面的復制代碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM