Validating workflow activity metadata

There are several options for validating properties on a custom activity.

Besides the possibility of using an ActivityValidator as described here we can also use the ValidationOptionAttribute. Now the ValidationOptionAttribute isn’t useful all the time and only for a limited set of properties.

First of all the limited set of properties. This will only work for dependency properties defined with DependencyPropertyOptions.Metadata. This makes them metadata and they cannot be changed at runtime, only design time.

The second is the limitation in that is can only enforce a required field. No specific values or even an error tekst.

So using this is a little weird to. With the ValidationOptionAttribute being an attribite the first thing that comes to mind is decorating the property with it. Well that doesn’t seem to do anything [:(].

[ValidationOption(ValidationOption.Required)]
public string MyMetadataProperty
{
    get
    {
        return ((string)(base.GetValue(ValidatedActivity.MyMetadataPropertyProperty)));
    }
    set
    {
        base.SetValue(ValidatedActivity.MyMetadataPropertyProperty, value);
    }
}

No in fact what you need to do is add it to the DependencyProperty constructor like this:


public static DependencyPropertyMyMetadataPropertyProperty =
    DependencyProperty.Register(“MyMetadataProperty”,
    typeof(string),
    typeof(ValidatedActivity),
    newPropertyMetadata(DependencyPropertyOptions.Metadata,
        newAttribute[] { newValidationOptionAttribute ValidationOption.Required) }));


Not very inuitive at all.

I guess the only benefit of this is not having to include a ActivityValidator but as far as I am concerned this is not a big benefit.

Enjoy!



www.TheProblemSolver.nl
http://wiki.WindowsWorkflowFoundation.eu

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>