'Custom Activites in Workflow Foundation dynamic Argument Validation
I have build a custom activity for Workflow Foundation which works exactly as exprected and I'mno implementing some validation on the arguments.
I have 4 arguments, the first 2 File_Location and CheckIn are required, and the validation [RequiredArgument] works fine. Is there a way of making the last 2 arguments CheckInComment and chekintype required if CheckIn is true.
public sealed class File_Upload : CodeActivity
{
[Category("Input")]
[DisplayName("Location of file to upload")]
[RequiredArgument]
public InArgument<string> File_Location { get; set; }
[Category("Input")]
[DisplayName("Check in file?")]
[RequiredArgument]
public InArgument<bool> CheckIn { get; set; }
[Category("Input")]
[DisplayName("Check in comment")]
//Required if CheckIn == True
public InArgument<string> CheckInComment { get; set; }
[Category("Input")]
[DisplayName("Check in type")]
//Required if CheckIn == True
public InArgument<CheckinType> chekintype { get; set; }
protected override void Execute(CodeActivityContext context)
{
//MY CODE
}
}
Solution 1:[1]
I don't think there's a way to do this exactly.
You could check at runtime though and throw an ArgumentException if the conditionally required fields aren't provided.
Another option is to have 2 activities, eg. File_Upload_WithCheckIn and File_Upload_WithoutCheckIn and only have the required arguments on the first one.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PGO |
