TimeSpanValidatorAttribute 类

定义

以声明方式指示 .NET 对配置属性执行时间验证。 此类不能被继承。

public ref class TimeSpanValidatorAttribute sealed : System::Configuration::ConfigurationValidatorAttribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class TimeSpanValidatorAttribute : System.Configuration.ConfigurationValidatorAttribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type TimeSpanValidatorAttribute = class
    inherit ConfigurationValidatorAttribute
Public NotInheritable Class TimeSpanValidatorAttribute
Inherits ConfigurationValidatorAttribute
继承
TimeSpanValidatorAttribute
属性

示例

以下示例演示如何使用 TimeSpanValidatorAttribute 特性修饰自定义ConfigurationSection对象的属性。

[ConfigurationProperty("maxIdleTime",
    DefaultValue = "0:10:0",
    IsRequired = false)]
[TimeSpanValidator(MinValueString = "0:0:30",
    MaxValueString = "5:00:0",
    ExcludeRange = false)]
public TimeSpan MaxIdleTime
{
    get
    {
        return (TimeSpan)this["maxIdleTime"];
    }
    set
    {
        this["maxIdleTime"] = value;
    }
}
<ConfigurationProperty("maxIdleTime", _
DefaultValue:="0:10:0", _
IsRequired:=False), _
TimeSpanValidator(MinValueString:="0:0:30", _
MaxValueString:="5:00:0", _
ExcludeRange:=False)> _
Public Property MaxIdleTime() As TimeSpan
    Get
        Return CType(Me("maxIdleTime"), TimeSpan)
    End Get
    Set(ByVal value As TimeSpan)
        Me("maxIdleTime") = value
    End Set
End Property

以下示例是配置文件的摘录,其中包含上一个示例使用的自定义节。

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">  
  <configSections>  
    <section name="custom" type="Microsoft.Samples.AspNet.Configuration.SampleSection, ConfigurationValidatorAttribute" />  
  </configSections>  
  <custom fileName="NewFile.txt" maxSize="1000" maxAttempts="101" maxUsers="2500" maxIdleTime="00:15:00" />  
</configuration>  

注解

使用 TimeSpanValidatorAttribute 属性来修饰配置属性。 这是为了指示 .NET 使用 TimeSpanValidator 类验证 属性,并将修饰参数的值传递给它。

只能将对象应用于 TimeSpanValidatorAttribute 属性类型。

构造函数

TimeSpanValidatorAttribute()

初始化 TimeSpanValidatorAttribute 类的新实例。

字段

TimeSpanMaxValue

获取允许的绝对最大值。

TimeSpanMinValue

获取允许的绝对最小值。

属性

ExcludeRange

获取或设置一个值,指示在 MinValueStringMaxValueString 所定义的范围内是包含还是排除整数。

MaxValue

获取 TimeSpan 的绝对最大值。

MaxValueString

获取或设置 TimeSpan 的相对最大值。

MinValue

获取 TimeSpan 的绝对最小值。

MinValueString

获取或设置 TimeSpan 的相对最小值。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)
ValidatorInstance

获取 TimeSpanValidator 类的实例。

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)

适用于

另请参阅