ActivityValidator.Validate(ValidationManager, Object) Metodo

Definizione

Verifica che l'attività specificata è valida.

public:
 override System::Workflow::ComponentModel::Compiler::ValidationErrorCollection ^ Validate(System::Workflow::ComponentModel::Compiler::ValidationManager ^ manager, System::Object ^ obj);
public override System.Workflow.ComponentModel.Compiler.ValidationErrorCollection Validate (System.Workflow.ComponentModel.Compiler.ValidationManager manager, object obj);
override this.Validate : System.Workflow.ComponentModel.Compiler.ValidationManager * obj -> System.Workflow.ComponentModel.Compiler.ValidationErrorCollection
Public Overrides Function Validate (manager As ValidationManager, obj As Object) As ValidationErrorCollection

Parametri

manager
ValidationManager

Classe ValidationManager associata all'evento di convalida.

obj
Object

Oggetto Activity da convalidare.

Restituisce

ValidationErrorCollection

Oggetto ValidationErrorCollection che contiene gli errori o avvisi che si sono verificati durante la convalida.

Esempio

Nell'esempio seguente viene illustrato come eseguire l'override del metodo Validate per un oggetto ActivityValidator utilizzato per un'attività personalizzata che dispone di una sola proprietà di dipendenza denominata Msg di tipo String. Il validator personalizzato assicura che la proprietà Msg venga impostata. In caso contrario, il compilatore visualizza un errore quando il metodo Validate viene chiamato sull'oggetto ActivityValidator e la compilazione non riesce.

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

Commenti

Questo metodo chiama il metodo ValidateProperties per convalidare le proprietà della classe Activity.

Questo metodo convalida solo l'unicità della proprietà Name per la classe Activity se la classe Activity non è una classe Activity radice.

Si applica a