开发者

How to check validity the value of InArgument in a Workflow activity?

开发者 https://www.devze.com 2023-01-23 17:02 出处:网络
In WF4 custom activities, I understand you can add warning of validation error by checking some condition and add validation error, ex

In WF4 custom activities, I understand you can add warning of validation error by checking some condition and add validation error, ex

if(Arg == null)
metadata.AddValidationError("Null argument");

in CacheMetadata(metadata)

My question if what if you want to check the content of the argument itself, for example you wan开发者_JAVA技巧t to check whether the value of Arg (an InArgument<String>) contains exactly 8 characters, and add validation error otherwise? Is this possible? How?


You won't get the actual data until the activity executes so you would need to do these checks in the Execute method at runtime. And depending on your preference and needs you can either set an error code OutArgument or throw an exception that can be caught in the workflow.


you can do it like this to validate the value:

public InArgument<int> MaxTimes { set; get; }


 protected override void CacheMetadata(NativeActivityMetadata metadata)
 {
     base.CacheMetadata(metadata);

     if (((System.Activities.Expressions.Literal<int>)(MaxTimes.Expression)).Value <= 1)
      {
        metadata.AddValidationError("must bigger than 1");       
      }
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消