IntegerValidatorAttribute.ValidatorInstance 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 IntegerValidator 类的实例。
public:
virtual property System::Configuration::ConfigurationValidatorBase ^ ValidatorInstance { System::Configuration::ConfigurationValidatorBase ^ get(); };
public override System.Configuration.ConfigurationValidatorBase ValidatorInstance { get; }
member this.ValidatorInstance : System.Configuration.ConfigurationValidatorBase
Public Overrides ReadOnly Property ValidatorInstance As ConfigurationValidatorBase
属性值
ConfigurationValidatorBase 验证程序实例。
示例
下面的示例演示如何使用 ValidatorInstance 属性。
ConfigurationValidatorBase valBase;
IntegerValidatorAttribute intValAttr;
intValAttr = new IntegerValidatorAttribute();
long badValue = 10;
int goodValue = 10;
try
{
valBase = intValAttr.ValidatorInstance;
valBase.Validate(goodValue);
// valBase.Validate(badValue);
}
catch (ArgumentException e)
{
// Display error message.
string msg = e.ToString();
#if DEBUG
Console.WriteLine(msg);
#endif
}
Dim valBase As ConfigurationValidatorBase
Dim intValAttr As IntegerValidatorAttribute
intValAttr = New IntegerValidatorAttribute()
Dim badValue As Long = 10
Dim goodValue As Integer = 10
Try
valBase = intValAttr.ValidatorInstance
valBase.Validate(goodValue)
' valBase.Validate(badValue);
Catch e As ArgumentException
' Display error message.
Dim msg As String = e.ToString()
#If DEBUG Then
Console.WriteLine(msg)
#End If
End Try '
注解
使用 ValidatorInstance 属性通过调用其 Validate 方法执行字符串验证。