.netvalidationworkflow-foundation-4workflow-activity

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


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 want to check whether the value of Arg (an InArgument<String>) contains exactly 8 characters, and add validation error otherwise? Is this possible? How?


Solution

  • 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.