ValidationError 類別

定義

表示所有驗證錯誤的基底類別。Represents the base class for all validation errors.

public ref class ValidationError sealed
[System.Serializable]
public sealed class ValidationError
type ValidationError = class
Public NotInheritable Class ValidationError
繼承
ValidationError
屬性

範例

下列範例將示範如何在自訂驗證常式中建立及管理驗證錯誤。The following example shows how to create and manipulate validation errors as part of a custom validation routine.

這個程式碼範例是 SendEMailActivity.cs 檔案中<傳送郵件 SDK>範例的一部分。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

備註

注意

此資料討論已被汰換的類型及命名空間。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.

建構函式

ValidationError(String, Int32)

初始化 ValidationError 類別的新執行個體,初始化這個執行個體的錯誤文字和錯誤代碼。Initializes a new instance of the ValidationError class; initializes the error text and error numbers for this instance.

ValidationError(String, Int32, Boolean)

初始化 ValidationError 類別的新執行個體,初始化這個執行個體的錯誤文字、錯誤代碼和錯誤型別。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)

初始化 ValidationError 類別的新執行個體,初始化與錯誤相關聯的錯誤文字、錯誤代碼、錯誤型別和屬性名稱。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.

屬性

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

取得與這個執行個體相關之使用者定義資料的定義與儲存區的 IDictionaryGets an IDictionary for the definition and storage of user-defined data related to this instance.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetNotSetValidationError(String)

建立新的驗證錯誤,這個驗證錯誤是為未設定的屬性之錯誤型別定義的。Creates a new validation error defined for the error type of a property not being set.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

提供這個執行個體的字串表示,其中加入錯誤型別 (錯誤或警告)、錯誤代碼和錯誤文字。Provides a string representation of this instance incorporating the error type (error or warning) the error number and the error text.

適用於