次の方法で共有


ActivityValidator.Validate(ValidationManager, Object) メソッド

定義

指定されたアクティビティが有効であることを検証します。

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

パラメーター

manager
ValidationManager

検証処理に関連付けられた ValidationManager

obj
Object

検証する Activity

戻り値

ValidationErrorCollection

検証中に発生したエラーまたは警告を格納している ValidationErrorCollection オブジェクト。

次の例は、Validate 型の ActivityValidator という名前の単一の依存関係プロパティが含まれるカスタム アクティビティで使用される MsgString メソッドをオーバーライドする方法を示しています。 カスタム検証によって Msg プロパティが設定されます。 設定されていない場合、ValidateActivityValidator メソッドが呼び出された時点でエラーが表示され、コンパイルは失敗します。

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

注釈

このメソッドは ValidateProperties を呼び出して、Activity のプロパティを検証します。

Name がルート Activity でなければ、Activity 間の Activity の一意性のみを検証します。

適用対象