ValidationErrorCollection.HasErrors Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Geeft aan of de verzameling objecten bevat ValidationError die compilatiefouten aangeven.
public:
property bool HasErrors { bool get(); };
public bool HasErrors { get; }
member this.HasErrors : bool
Public ReadOnly Property HasErrors As Boolean
Waarde van eigenschap
true als de activiteit validatiefouten heeft gegenereerd; anders, false.
Voorbeelden
In het volgende voorbeeld ziet u hoe u een validatiefoutverzameling maakt en bewerkt als onderdeel van een aangepaste validatieroutine.
Dit codevoorbeeld maakt deel uit van het voorbeeld e-mail-SDK verzenden en is afkomstig uit het SendMailActivity.cs-bestand. Zie E-mailactiviteit verzenden voor meer informatie.
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
Opmerkingen
Als een Activity waarschuwing is gegenereerd, wordt de waarschuwing beschouwd als een fout in de context van deze eigenschap.