StringValidatorAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
以声明方式指示 .NET 对配置属性执行字符串验证。 此类不能被继承。
public ref class StringValidatorAttribute sealed : System::Configuration::ConfigurationValidatorAttribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class StringValidatorAttribute : System.Configuration.ConfigurationValidatorAttribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type StringValidatorAttribute = class
inherit ConfigurationValidatorAttribute
Public NotInheritable Class StringValidatorAttribute
Inherits ConfigurationValidatorAttribute
- 继承
- 属性
示例
以下示例演示如何使用ConfigurationSection对象修饰自定义StringValidatorAttribute对象的属性。
[ConfigurationProperty("fileName", DefaultValue = "default.txt",
IsRequired = true, IsKey = false)]
[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
MinLength = 1, MaxLength = 60)]
public string FileName
{
get
{
return (string)this["fileName"];
}
set
{
this["fileName"] = value;
}
}
<ConfigurationProperty("fileName", _
DefaultValue:="default.txt", _
IsRequired:=True, _
IsKey:=False), _
StringValidator( _
InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\", _
MinLength:=1, _
MaxLength:=60)> _
Public Property FileName() As String
Get
Return CStr(Me("fileName"))
End Get
Set(ByVal value As String)
Me("fileName") = value
End Set
End Property
注解
使用 StringValidatorAttribute 修饰配置属性。 这是指示.NET使用 StringValidator验证属性,并将其传递给修饰参数的值。
只能将对象应用于 StringValidatorAttribute 属性类型。
构造函数
| 名称 | 说明 |
|---|---|
| StringValidatorAttribute() |
初始化 StringValidatorAttribute 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| InvalidCharacters |
获取或设置属性的无效字符。 |
| MaxLength |
获取或设置允许字符串分配给属性的最大长度。 |
| MinLength |
获取或设置要分配给该属性的字符串的最小允许值。 |
| TypeId |
在派生类中实现时,获取此 Attribute的唯一标识符。 (继承自 Attribute) |
| ValidatorInstance |
获取类的 StringValidator 实例。 |
| ValidatorType |
获取验证程序属性的类型。 (继承自 ConfigurationValidatorAttribute) |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
返回一个值,该值指示此实例是否等于指定对象。 (继承自 Attribute) |
| GetHashCode() |
返回此实例的哈希代码。 (继承自 Attribute) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| IsDefaultAttribute() |
在派生类中重写时,指示此实例的值是否为派生类的默认值。 (继承自 Attribute) |
| Match(Object) |
在派生类中重写时,返回一个值,该值指示此实例是否等于指定对象。 (继承自 Attribute) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |
显式接口实现
| 名称 | 说明 |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
将一组名称映射为对应的一组调度标识符。 (继承自 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
检索对象的类型信息,该信息可用于获取接口的类型信息。 (继承自 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
检索对象提供的类型信息接口的数量(0 或 1)。 (继承自 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供对对象公开的属性和方法的访问。 (继承自 Attribute) |