Welcome to Microsoft .NET Framework 3.0 Community (NetFx3)

The .NET Framework is Microsoft's managed code programming model for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of business processes.

Learn More...

WF Community Bloggers

Sunday, May 18, 2008 - Posts

  • Validating custom activities in the Workflow designer

    Create a derived class from ActivityValidator and add it to your custom activity using the ActivityValidatorAttribute. For example: [ ActivityValidator ( typeof ( ValidatedActivityValidator ))] public partial class ValidatedActivity : SequenceActivity { } The validator class now look like this: class ValidatedActivityValidator : ActivityValidator { public override ValidationErrorCollection Validate( ValidationManager manager, object obj) { ValidationErrorCollection result = base .Validate(manager, obj); ValidatedActivity activity = obj as ValidatedActivity ; if (activity != null && activity.Parent != null ) { if (activity.AValueBetween1And250 < 1) result.Add( new ValidationError ( "The value is to small" , 102, false , "AValueBetween1And250" )); if (activity.AValueBetween1And250 > 250) result.Add( new ValidationError ( "The value is to big" , 103, true , "AValueBetween1And250" )); } return result; } } Note that the object parameter (obj) is the activity to be validated. The ActivityValidator type contains two virtual function Validate and ValidateProperties. It doesn't really matter which you use as the Validate actually calls the ValidateProperties function. This means they are both called at the same time unless you change the behavior by not calling the base.Validate() function. To indicate errors or warnings you can add a ValidationError object to the ValidationErrorCollection to be returned. Adding the property name Read More...

Copyright © 2007 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us