【问题标题】:How do I add a constraint to a declarative workflow in WF 4.5?如何在 WF 4.5 中向声明性工作流添加约束?
【发布时间】:2014-08-15 16:48:15
【问题描述】:

是否有任何示例说明如何在 Windows Workflow Foundation 4.5 工作流中创建声明性约束?我查看了samples on MSDN,样本中没有任何声明性约束的示例。

【问题讨论】:

    标签: constraints workflow-foundation


    【解决方案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"),
                    }
                }
            };            
        }
    }
    

    希望以上有所帮助。

    【讨论】:

    • 这是从 MSDN 页面复制和粘贴的。我要的是工作流中的视觉示例,而不是代码中的示例。
    猜你喜欢
    • 2019-03-21
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    相关资源
    最近更新 更多