ערוך

שתף באמצעות


ValidationError Class

Definition

Represents the base class for all validation errors.

public ref class ValidationError sealed
[System.Serializable]
public sealed class ValidationError
[<System.Serializable>]
type ValidationError = class
Public NotInheritable Class ValidationError
Inheritance
ValidationError
Attributes

Examples

The following example shows how to create and manipulate validation errors as part of a custom validation routine.

This code example is part of the Send Mail SDK Sample and is from the SendEMailActivity.cs file. For more information, see Send Mail Activity.

private void ValidateEmailProperties(ValidationErrorCollection validationErrors, SendEmailActivity activity)
{
    // Validate the To property
    if (string.IsNullOrEmpty(activity.To))
    {
        validationErrors.Add(ValidationError.GetNotSetValidationError(SendEmailActivity.ToProperty.Name));
    }
    else if (!activity.To.Contains("@"))
    {
        validationErrors.Add(new ValidationError("Invalid To email address", InvalidToAddress, false, SendEmailActivity.ToProperty.Name));
    }

    // Validate the From property
    if (string.IsNullOrEmpty(activity.From))
    {
        validationErrors.Add(ValidationError.GetNotSetValidationError(SendEmailActivity.FromProperty.Name));
    }
    else if (!activity.From.Contains("@"))
    {
        validationErrors.Add(new ValidationError("Invalid From email address", InvalidFromAddress, false, SendEmailActivity.FromProperty.Name));
    }
}
Private Sub ValidateEmailProperties(ByVal validationErrors As ValidationErrorCollection, ByVal activity As SendEmailActivity)
    'Validate the To property
    If String.IsNullOrEmpty(activity.EmailTo) Then
        Dim validationError As ValidationError = System.Workflow.ComponentModel.Compiler.ValidationError.GetNotSetValidationError(SendEmailActivity.ToProperty.Name)
        validationErrors.Add(validationError)
    ElseIf Not activity.EmailTo.Contains("@") Then
        Dim validationError As New ValidationError("Invalid To email address", _
          InvalidToAddress, False, SendEmailActivity.ToProperty.Name)
        validationErrors.Add(validationError)
    End If

    ' Validate the From property
    If String.IsNullOrEmpty(activity.FromEmail) Then
        validationErrors.Add(ValidationError.GetNotSetValidationError(SendEmailActivity.FromEmailProperty.Name))
    ElseIf Not activity.FromEmail.Contains("@") Then
        Dim validationError As New ValidationError("Invalid From email address", _
            InvalidFromAddress, False, SendEmailActivity.FromEmailProperty.Name)
        validationErrors.Add(validationError)
    End If
End Sub

Remarks

Note

This material discusses types and namespaces that are obsolete. For more information, see Deprecated Types in Windows Workflow Foundation 4.5.

Constructors

ValidationError(String, Int32)

Initializes a new instance of the ValidationError class; initializes the error text and error numbers for this instance.

ValidationError(String, Int32, Boolean)

Initializes a new instance of the ValidationError class, initializes the error text, error number and error type for this instance.

ValidationError(String, Int32, Boolean, String)

Initializes a new instance of the ValidationError class, initializing the error text, the error number, the error type and the property name associated with the error.

Properties

ErrorNumber

Gets the error number of this instance.

ErrorText

Gets the error text for this instance.

IsWarning

Gets a value that indicates whether this instance is a warning.

PropertyName

Gets or sets the name of the property that failed to validate.

UserData

Gets an IDictionary for the definition and storage of user-defined data related to this instance.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetNotSetValidationError(String)

Creates a new validation error defined for the error type of a property not being set.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Provides a string representation of this instance incorporating the error type (error or warning) the error number and the error text.

Applies to