Partager via


ValidationErrorCollection Constructeurs

Définition

Initialise une nouvelle instance de la classe ValidationErrorCollection.

Surcharges

ValidationErrorCollection()

Initialise une nouvelle instance de la classe ValidationErrorCollection.

ValidationErrorCollection(IEnumerable<ValidationError>)

Initialise une nouvelle instance de la ValidationErrorCollection classe à partir d’une IEnumerable collection de type ValidationError.

ValidationErrorCollection(ValidationErrorCollection)

Initialise une nouvelle instance de la classe ValidationErrorCollection à l'aide de ValidationErrorCollection.

Remarques

L'exemple suivant illustre la création et la manipulation d'une collection d'erreurs de validation dans le cadre d'une routine de validation personnalisée.

Cet exemple de code fait partie de l’exemple de Kit de développement logiciel (SDK) Send Email et provient du fichier SendMailActivity.cs. Pour plus d’informations, consultez Activité d’envoi de courrier.

public class SendEmailValidator : System.Workflow.ComponentModel.Compiler.ActivityValidator
{
    // Define private constants for the Validation Errors
    private const int InvalidToAddress = 1;
    private const int InvalidFromAddress = 2;
    private const int InvalidSMTPPort = 3;

    //customizing the default activity validation
    public override ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj)
    {

        // Create a new collection for storing the validation errors
        ValidationErrorCollection validationErrors = base.ValidateProperties(manager, obj);

        SendEmailActivity activity = obj as SendEmailActivity;
        if (activity != null)
        {
            // Validate the Email and SMTP Properties
            this.ValidateEmailProperties(validationErrors, activity);
            this.ValidateSMTPProperties(validationErrors, activity);
        }
        return validationErrors;
    }
Public Class SendEmailValidator
    Inherits System.Workflow.ComponentModel.Compiler.ActivityValidator

    ' Define private constants for the Validation Errors 
    Private Const InvalidToAddress As Integer = 1
    Private Const InvalidFromAddress As Integer = 2
    Private Const InvalidSMTPPort As Integer = 3

    ' customizing the default activity validation
    Public Overrides Function ValidateProperties(ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection

        ' Create a new collection for storing the validation errors
        Dim validationErrors As New ValidationErrorCollection()

        Dim activity As SendEmailActivity = TryCast(obj, SendEmailActivity)

        If activity IsNot Nothing Then

            ' Validate the Email and SMTP Properties
            Me.ValidateEmailProperties(validationErrors, activity)
            Me.ValidateSMTPProperties(validationErrors, activity)

            ' Raise an exception if we have ValidationErrors
            If validationErrors.HasErrors Then

                Dim validationErrorsMessage As String = String.Empty

                For Each validationError As ValidationError In validationErrors
                    validationErrorsMessage += _
                        String.Format("Validation Error:  Number 0} - '1}' \n", _
                        validationError.ErrorNumber, validationError.ErrorText)
                Next

                ' Throw a new exception with the validation errors.
                Throw New InvalidOperationException(validationErrorsMessage)
            End If
        End If
        Return validationErrors
    End Function

ValidationErrorCollection()

Initialise une nouvelle instance de la classe ValidationErrorCollection.

public:
 ValidationErrorCollection();
public ValidationErrorCollection ();
Public Sub New ()

Exemples

L'exemple suivant illustre la création et la manipulation d'une collection d'erreurs de validation dans le cadre d'une routine de validation personnalisée.

Cet exemple de code fait partie de l’exemple de Kit de développement logiciel (SDK) Send Email et provient du fichier SendMailActivity.cs. Pour plus d’informations, consultez Activité d’envoi de courrier.

public class SendEmailValidator : System.Workflow.ComponentModel.Compiler.ActivityValidator
{
    // Define private constants for the Validation Errors
    private const int InvalidToAddress = 1;
    private const int InvalidFromAddress = 2;
    private const int InvalidSMTPPort = 3;

    //customizing the default activity validation
    public override ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj)
    {

        // Create a new collection for storing the validation errors
        ValidationErrorCollection validationErrors = base.ValidateProperties(manager, obj);

        SendEmailActivity activity = obj as SendEmailActivity;
        if (activity != null)
        {
            // Validate the Email and SMTP Properties
            this.ValidateEmailProperties(validationErrors, activity);
            this.ValidateSMTPProperties(validationErrors, activity);
        }
        return validationErrors;
    }
Public Class SendEmailValidator
    Inherits System.Workflow.ComponentModel.Compiler.ActivityValidator

    ' Define private constants for the Validation Errors 
    Private Const InvalidToAddress As Integer = 1
    Private Const InvalidFromAddress As Integer = 2
    Private Const InvalidSMTPPort As Integer = 3

    ' customizing the default activity validation
    Public Overrides Function ValidateProperties(ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection

        ' Create a new collection for storing the validation errors
        Dim validationErrors As New ValidationErrorCollection()

        Dim activity As SendEmailActivity = TryCast(obj, SendEmailActivity)

        If activity IsNot Nothing Then

            ' Validate the Email and SMTP Properties
            Me.ValidateEmailProperties(validationErrors, activity)
            Me.ValidateSMTPProperties(validationErrors, activity)

            ' Raise an exception if we have ValidationErrors
            If validationErrors.HasErrors Then

                Dim validationErrorsMessage As String = String.Empty

                For Each validationError As ValidationError In validationErrors
                    validationErrorsMessage += _
                        String.Format("Validation Error:  Number 0} - '1}' \n", _
                        validationError.ErrorNumber, validationError.ErrorText)
                Next

                ' Throw a new exception with the validation errors.
                Throw New InvalidOperationException(validationErrorsMessage)
            End If
        End If
        Return validationErrors
    End Function

S’applique à

ValidationErrorCollection(IEnumerable<ValidationError>)

Initialise une nouvelle instance de la ValidationErrorCollection classe à partir d’une IEnumerable collection de type ValidationError.

public:
 ValidationErrorCollection(System::Collections::Generic::IEnumerable<System::Workflow::ComponentModel::Compiler::ValidationError ^> ^ value);
public ValidationErrorCollection (System.Collections.Generic.IEnumerable<System.Workflow.ComponentModel.Compiler.ValidationError> value);
new System.Workflow.ComponentModel.Compiler.ValidationErrorCollection : seq<System.Workflow.ComponentModel.Compiler.ValidationError> -> System.Workflow.ComponentModel.Compiler.ValidationErrorCollection
Public Sub New (value As IEnumerable(Of ValidationError))

Paramètres

Exceptions

value a la valeur null.

S’applique à

ValidationErrorCollection(ValidationErrorCollection)

Initialise une nouvelle instance de la classe ValidationErrorCollection à l'aide de ValidationErrorCollection.

public:
 ValidationErrorCollection(System::Workflow::ComponentModel::Compiler::ValidationErrorCollection ^ value);
public ValidationErrorCollection (System.Workflow.ComponentModel.Compiler.ValidationErrorCollection value);
new System.Workflow.ComponentModel.Compiler.ValidationErrorCollection : System.Workflow.ComponentModel.Compiler.ValidationErrorCollection -> System.Workflow.ComponentModel.Compiler.ValidationErrorCollection
Public Sub New (value As ValidationErrorCollection)

Paramètres

value
ValidationErrorCollection

ValidationErrorCollection qui contient des erreurs de validation.

Exemples

L'exemple suivant illustre la création et la manipulation d'une collection d'erreurs de validation dans le cadre d'une routine de validation personnalisée.

Cet exemple de code fait partie de l’exemple de Kit de développement logiciel (SDK) Send Email et provient du fichier SendMailActivity.cs. Pour plus d’informations, consultez Activité d’envoi de courrier.

public class SendEmailValidator : System.Workflow.ComponentModel.Compiler.ActivityValidator
{
    // Define private constants for the Validation Errors
    private const int InvalidToAddress = 1;
    private const int InvalidFromAddress = 2;
    private const int InvalidSMTPPort = 3;

    //customizing the default activity validation
    public override ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj)
    {

        // Create a new collection for storing the validation errors
        ValidationErrorCollection validationErrors = base.ValidateProperties(manager, obj);

        SendEmailActivity activity = obj as SendEmailActivity;
        if (activity != null)
        {
            // Validate the Email and SMTP Properties
            this.ValidateEmailProperties(validationErrors, activity);
            this.ValidateSMTPProperties(validationErrors, activity);
        }
        return validationErrors;
    }
Public Class SendEmailValidator
    Inherits System.Workflow.ComponentModel.Compiler.ActivityValidator

    ' Define private constants for the Validation Errors 
    Private Const InvalidToAddress As Integer = 1
    Private Const InvalidFromAddress As Integer = 2
    Private Const InvalidSMTPPort As Integer = 3

    ' customizing the default activity validation
    Public Overrides Function ValidateProperties(ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection

        ' Create a new collection for storing the validation errors
        Dim validationErrors As New ValidationErrorCollection()

        Dim activity As SendEmailActivity = TryCast(obj, SendEmailActivity)

        If activity IsNot Nothing Then

            ' Validate the Email and SMTP Properties
            Me.ValidateEmailProperties(validationErrors, activity)
            Me.ValidateSMTPProperties(validationErrors, activity)

            ' Raise an exception if we have ValidationErrors
            If validationErrors.HasErrors Then

                Dim validationErrorsMessage As String = String.Empty

                For Each validationError As ValidationError In validationErrors
                    validationErrorsMessage += _
                        String.Format("Validation Error:  Number 0} - '1}' \n", _
                        validationError.ErrorNumber, validationError.ErrorText)
                Next

                ' Throw a new exception with the validation errors.
                Throw New InvalidOperationException(validationErrorsMessage)
            End If
        End If
        Return validationErrors
    End Function

S’applique à