ActivityValidator 类

定义

警告

此 API 现已过时。

DependencyObjectValidator 的派生类,它是所有活动验证程序组件的基类。Derivative of DependencyObjectValidator that is a base class for all activity validator components.

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
Public Class ActivityValidator
Inherits DependencyObjectValidator
继承
派生
属性

示例

下面的示例演示一个用于自定义活动的完整的 ActivityValidatorThe following example shows a complete ActivityValidator used for a custom activity. 自定义活动是一个 ConsoleWriteLineActivity 活动,它有一个类型为 Msg 的依赖项属性,其名称为 StringThe custom activity is a ConsoleWriteLineActivity activity that has a single dependency property named Msg of type String. 验证程序可以确保设置了 Msg 属性。The validator ensures that the Msg property is set. 如果未设置,则在对 Validate 调用 ActivityValidator 方法时,编译器将显示错误,且编译将失败。If it is not set, the compiler displays an error when the Validate method is called on the ActivityValidator and the compilation fails.

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

注解

备注

本材料讨论的类型和命名空间已废弃不用。This material discusses types and namespaces that are obsolete. 有关详细信息,请参阅 Windows Workflow Foundation 4.5 中弃用的类型For more information, see Deprecated Types in Windows Workflow Foundation 4.5.

构造函数

ActivityValidator()

初始化 ActivityValidator 类的新实例。Initializes a new instance of the ActivityValidator class.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetFullPropertyName(ValidationManager)

可提取完整属性名的帮助器方法。Helper method to extract the full property name.

(继承自 Validator)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
Validate(ValidationManager, Object)

验证给定的活动是否有效。Verifies that the given activity is valid.

ValidateActivityChange(Activity, ActivityChangeAction)

在派生类中重写时,根据正在被添加或删除的指定 Activity 来验证更改。When overridden in a derived class, validates a change based on a specified Activity being added or removed. 应用在动态更新过程中对工作流作出的更改时调用此函数。This function is called during the application of changes that are made to the workflow during dynamic updates.

(继承自 Validator)
ValidateProperties(ValidationManager, Object)

自动验证特定对象属性的帮助器方法。Helper method to automatically validate the specific objects properties.

(继承自 Validator)
ValidateProperty(PropertyInfo, Object, Object, ValidationManager)

对属性执行验证并返回包含验证结果的 ValidationErrorCollectionPerforms validation on a property and returns a ValidationErrorCollection that contains the results of that validation.

(继承自 Validator)

适用于