ActivityValidator.Validate(ValidationManager, Object) Méthode

Définition

Vérifie que l'activité donnée est valide.

public override System.Workflow.ComponentModel.Compiler.ValidationErrorCollection Validate (System.Workflow.ComponentModel.Compiler.ValidationManager manager, object obj);

Paramètres

manager
ValidationManager

ValidationManager associé à la validation.

obj
Object

Activity à valider.

Retours

ValidationErrorCollection

Un objet ValidationErrorCollection qui contient les erreurs ou les avertissements qui se sont produits pendant la validation.

Exemples

L'exemple suivant montre comment substituer la méthode Validate pour un ActivityValidator utilisé pour une activité personnalisée qui a une propriété de dépendance unique nommée Msg de type String. Le validateur personnalisé garantit que la propriété Msg est définie. S'il n'est pas défini, le compilateur affiche une erreur lorsque la méthode Validate est appelée sur le ActivityValidator et la compilation échoue.

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;
}

Remarques

Cette méthode appelle ValidateProperties pour valider les propriétés de Activity.

Cette méthode valide seulement l'unicité de Name pour Activity si Activity n'est pas un Activityracine.

S’applique à