ValidationErrorCollection.HasErrors 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指出集合是否包含指出編譯錯誤的 ValidationError 物件。
public:
property bool HasErrors { bool get(); };
public bool HasErrors { get; }
member this.HasErrors : bool
Public ReadOnly Property HasErrors As Boolean
屬性值
如果活動已產生驗證錯誤,則為 true
,否則為 false
。
範例
下列範例將示範如何在自訂驗證常式中建立及管理驗證錯誤集合。
此程式碼範例是 Send Email SDK 範例的一部分,來自 SendMailActivity.cs 檔案。 如需詳細資訊,請參閱 傳送郵件活動。
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
備註
如果 Activity 已產生警告,則將警告視為此屬性內容中的錯誤。