Share via


ActivityValidator Classe

Definição

Cuidado

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

Derivado de DependencyObjectValidator que é uma classe base para todos os componentes do validador de atividade.

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
Herança
Derivado
Atributos

Exemplos

O exemplo a seguir mostra uma completa ActivityValidator usada para uma atividade personalizada. A atividade personalizada é uma ConsoleWriteLineActivity atividade que tem uma única propriedade de dependência nomeada Msg do tipo String. O validador garante que a Msg propriedade esteja definida. Se não estiver definido, o compilador exibirá um erro quando o Validate método for chamado e ActivityValidator a compilação falhar.

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

Comentários

Observação

Este material discute tipos e namespaces obsoletos. Para obter mais informações, consulte Deprecated Types in Windows Workflow Foundation 4.5 (Tipos preteridos no Windows Workflow Foundation 4.5).

Construtores

ActivityValidator()

Inicializa uma nova instância da classe ActivityValidator.

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetFullPropertyName(ValidationManager)

Método auxiliar para extrair o nome completo da propriedade.

(Herdado de Validator)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)
Validate(ValidationManager, Object)

Verifica se a atividade especificada é válida.

ValidateActivityChange(Activity, ActivityChangeAction)

Quando substituído em uma classe derivada, valida uma alteração com base em um Activity especificado que está sendo adicionado ou removido. Essa função é chamada durante a aplicação de alterações ao fluxo de trabalho durante atualizações dinâmicas.

(Herdado de Validator)
ValidateProperties(ValidationManager, Object)

Método auxiliar para validar automaticamente as propriedades de objetos específicos.

(Herdado de Validator)
ValidateProperty(PropertyInfo, Object, Object, ValidationManager)

Realiza a validação em uma propriedade e retorna um ValidationErrorCollection que contém os resultados dessa validação.

(Herdado de Validator)

Aplica-se a