Partager via


ActivityValidator Classe

Définition

Attention

The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*

Dérivée de DependencyObjectValidator qui est une classe de base pour tous les composants du validateur de l'activité.

public ref class ActivityValidator : System::Workflow::ComponentModel::Compiler::DependencyObjectValidator
public class ActivityValidator : System.Workflow.ComponentModel.Compiler.DependencyObjectValidator
[System.Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
public class ActivityValidator : System.Workflow.ComponentModel.Compiler.DependencyObjectValidator
type ActivityValidator = class
    inherit DependencyObjectValidator
[<System.Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")>]
type ActivityValidator = class
    inherit DependencyObjectValidator
Public Class ActivityValidator
Inherits DependencyObjectValidator
Héritage
Dérivé
Attributs

Exemples

L'exemple suivant illustre un ActivityValidator complet utilisé pour une activité personnalisée. L'activité personnalisée est une activité ConsoleWriteLineActivity qui possède une propriété de dépendance unique nommée Msg de type String. Le validateur 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.

class ConsoleWriteLineActivityValidator : ActivityValidator
{
    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;
    }
}
Class ConsoleWriteLineActivityValidator
    Inherits ActivityValidator

    Public Overrides Function Validate( _
        ByVal manager As System.Workflow.ComponentModel.Compiler.ValidationManager, _
        ByVal obj As Object) As System.Workflow.ComponentModel.Compiler.ValidationErrorCollection

        'Invoke the base class method implementation to
        'perform default validation.
        Dim errors As ValidationErrorCollection = MyBase.Validate(manager, obj)

        'Make sure there is an activity instance.
        Dim crw As ConsoleWriteLineActivity = CType(obj, ConsoleWriteLineActivity)
        If crw Is Nothing Then
            Throw New InvalidOperationException()
        End If

        '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 Is Nothing Then
            'Can skip the rest of the validation because
            'it deals with the hosting and the creation
            'of the activity.
            Return errors
        End If

        '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) And _
            crw.GetBinding(ConsoleWriteLineActivity.MsgProperty) Is Nothing Then

            errors.Add(New ValidationError("Msg is required", 100, False, "Msg"))

        End If

        Return errors
    End Function
End Class

Remarques

Notes

Ce document décrit les types et les espaces de noms qui sont obsolètes. Pour plus d’informations, consultez Types dépréciés dans Windows Workflow Foundation 4.5.

Constructeurs

ActivityValidator()

Initialise une nouvelle instance de la classe ActivityValidator.

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetFullPropertyName(ValidationManager)

Méthode d'assistance pour extraire le nom de propriété complet.

(Hérité de Validator)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)
Validate(ValidationManager, Object)

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

ValidateActivityChange(Activity, ActivityChangeAction)

En cas de substitution dans une classe dérivée, valide une modification selon le Activity spécifié qui est ajouté ou supprimé. Cette fonction est appelée pendant l'application des modifications apportées au workflow pendant des mises à jour dynamiques.

(Hérité de Validator)
ValidateProperties(ValidationManager, Object)

Méthode d'assistance pour valider automatiquement les propriétés d'objets spécifiques.

(Hérité de Validator)
ValidateProperty(PropertyInfo, Object, Object, ValidationManager)

Exécute une validation sur une propriété et retourne ValidationErrorCollection qui contient les résultats de cette validation.

(Hérité de Validator)

S’applique à