TimeSpanValidatorAttribute 类

定义

以声明的方式指示 .NET 对配置属性执行时间验证。Declaratively instructs .NET to perform time validation on a configuration property. 此类不能被继承。This class cannot be inherited.

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
属性

示例

下面的示例演示如何使用特性修饰自定义对象的属性 ConfigurationSection TimeSpanValidatorAttributeThe following example shows how to decorate the properties of a custom ConfigurationSection object using the TimeSpanValidatorAttribute attribute.

[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

下面的示例摘自一个配置文件,其中包含上一个示例使用的自定义部分。The following example is an excerpt of the configuration file that contains the custom section used by the previous sample.

<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 特性来修饰配置属性。You use the TimeSpanValidatorAttribute attribute to decorate a configuration property. 这是为了指导 .NET 使用类验证属性 TimeSpanValidator ,并向其传递修饰参数的值。This is to instruct .NET to validate the property using the TimeSpanValidator class and pass to it the value of the decorating parameters.

只能将对象应用于 TimeSpanValidatorAttribute 属性类型。You can apply TimeSpanValidatorAttribute objects to property types only.

构造函数

TimeSpanValidatorAttribute()

初始化 TimeSpanValidatorAttribute 类的新实例。Initializes a new instance of the TimeSpanValidatorAttribute class.

字段

TimeSpanMaxValue

获取允许的绝对最大值。Gets the absolute maximum value allowed.

TimeSpanMinValue

获取允许的绝对最小值。Gets the absolute minimum value allowed.

属性

ExcludeRange

获取或设置一个值,指示在 MinValueStringMaxValueString 所定义的范围内是包含还是排除整数。Gets or sets a value that indicates whether to include or exclude the integers in the range as defined by MinValueString and MaxValueString.

MaxValue

获取 TimeSpan 的绝对最大值。Gets the absolute maximum TimeSpan value.

MaxValueString

获取或设置 TimeSpan 的相对最大值。Gets or sets the relative maximum TimeSpan value.

MinValue

获取 TimeSpan 的绝对最小值。Gets the absolute minimum TimeSpan value.

MinValueString

获取或设置 TimeSpan 的相对最小值。Gets or sets the relative minimum TimeSpan value.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)
ValidatorInstance

获取 TimeSpanValidator 类的实例。Gets an instance of the TimeSpanValidator class.

ValidatorType

获取验证程序特性的类型。Gets the type of the validator attribute.

(继承自 ConfigurationValidatorAttribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅