ActivityValidator.Validate Method (ValidationManager, Object)


Verifies that the given activity is valid.

Namespace:   System.Workflow.ComponentModel.Compiler
Assembly:  System.Workflow.ComponentModel (in System.Workflow.ComponentModel.dll)

public override ValidationErrorCollection Validate(
	ValidationManager manager,
	object obj


Type: System.Workflow.ComponentModel.Compiler.ValidationManager

The ValidationManager associated with validation.

Type: System.Object

The Activity to be validated.

Return Value

Type: System.Workflow.ComponentModel.Compiler.ValidationErrorCollection

A ValidationErrorCollection object that contains any errors or warnings that occurred during validation.

This method calls ValidateProperties to validate the properties of the Activity.

This method only validates the uniqueness of the Name for the Activity if the Activity is not a root Activity.

The following example shows how to override the Validate method for an ActivityValidator used for a custom activity that has a single dependency property named Msg of type String. The custom validator ensures that the Msg property is set. If it is not set, the compiler displays an error when the Validate method is called on the ActivityValidator and the compilation fails.

public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
    // Invoke the base class method implementation to
    // perform default validation.
    ValidationErrorCollection errors = base.Validate(manager, obj);

    // Make sure there is an activity instance.
    ConsoleWriteLineActivity crw = obj as ConsoleWriteLineActivity;
    if (crw == null)
        throw new InvalidOperationException();

    // If the activity has no parent then this validation
    // is occurring during the compilation of the activity
    // and not during the hosting or creation of an
    // activity instance.
    if (crw.Parent == null)
        // Can skip the rest of the validation because
        // it deals with the hosting and the creation
        // of the activity.
        return errors;

    // Msg is required. Add a validation error if there is no
    // Msg specified or Msg is not bound to another property.
    if (string.IsNullOrEmpty(crw.Msg) &&
        crw.GetBinding(ConsoleWriteLineActivity.MsgProperty) == null)
        errors.Add(new ValidationError("Msg is required", 100, false, "Msg"));

    return errors;

.NET Framework
Available since 3.0
Return to top