ValidationError 构造函数
定义
初始化 ValidationError 类的新实例。Initializes a new instance of the ValidationError class.
重载
| 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. |
注解
下面的示例演示如何作为自定义验证例程的一部分来创建和操作验证错误。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
ValidationError(String, Int32)
初始化 ValidationError 类的新实例,同时初始化此实例的错误文本和错误号。Initializes a new instance of the ValidationError class; initializes the error text and error numbers for this instance.
public:
ValidationError(System::String ^ errorText, int errorNumber);
public ValidationError (string errorText, int errorNumber);
new System.Workflow.ComponentModel.Compiler.ValidationError : string * int -> System.Workflow.ComponentModel.Compiler.ValidationError
Public Sub New (errorText As String, errorNumber As Integer)
参数
- errorText
- String
此实例的关联错误文本。The associated error text for this instance.
- errorNumber
- Int32
此错误的错误号。The error number for this error.
适用于
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.
public:
ValidationError(System::String ^ errorText, int errorNumber, bool isWarning);
public ValidationError (string errorText, int errorNumber, bool isWarning);
new System.Workflow.ComponentModel.Compiler.ValidationError : string * int * bool -> System.Workflow.ComponentModel.Compiler.ValidationError
Public Sub New (errorText As String, errorNumber As Integer, isWarning As Boolean)
参数
- errorText
- String
此实例的关联错误文本。The associated error text for this instance.
- errorNumber
- Int32
此错误的错误号。The error number for this error.
- isWarning
- Boolean
一个布尔值,如果将错误视为警告,则为 true;否则为 false。A Boolean which is true if the error is considered a warning and false otherwise.
适用于
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.
public:
ValidationError(System::String ^ errorText, int errorNumber, bool isWarning, System::String ^ propertyName);
public ValidationError (string errorText, int errorNumber, bool isWarning, string propertyName);
new System.Workflow.ComponentModel.Compiler.ValidationError : string * int * bool * string -> System.Workflow.ComponentModel.Compiler.ValidationError
Public Sub New (errorText As String, errorNumber As Integer, isWarning As Boolean, propertyName As String)
参数
- errorText
- String
此实例的关联错误文本。The associated error text for this instance.
- errorNumber
- Int32
此错误的错误号。The error number for this error.
- isWarning
- Boolean
一个布尔值,如果将错误视为警告,则为 true;否则为 false。A Boolean which is true if the error is considered a warning and false otherwise.
- propertyName
- String
与错误关联的属性名称。The name of the property associated with this error.