RangeAttribute 构造函数

定义

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

重载

RangeAttribute(Double, Double)

使用指定的最小值和最大值初始化 RangeAttribute 类的一个新实例。Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

RangeAttribute(Int32, Int32)

使用指定的最小值和最大值初始化 RangeAttribute 类的一个新实例。Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

RangeAttribute(Type, String, String)

使用指定的最小值和最大值以及特定类型初始化 RangeAttribute 类的一个新实例。Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values and the specific type.

RangeAttribute(Double, Double)

使用指定的最小值和最大值初始化 RangeAttribute 类的一个新实例。Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

public:
 RangeAttribute(double minimum, double maximum);
public RangeAttribute (double minimum, double maximum);
new System.ComponentModel.DataAnnotations.RangeAttribute : double * double -> System.ComponentModel.DataAnnotations.RangeAttribute
Public Sub New (minimum As Double, maximum As Double)

参数

minimum
Double

指定数据字段值所允许的最小值。Specifies the minimum value allowed for the data field value.

maximum
Double

指定数据字段值所允许的最大值。Specifies the maximum value allowed for the data field value.

适用于

RangeAttribute(Int32, Int32)

使用指定的最小值和最大值初始化 RangeAttribute 类的一个新实例。Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

public:
 RangeAttribute(int minimum, int maximum);
public RangeAttribute (int minimum, int maximum);
new System.ComponentModel.DataAnnotations.RangeAttribute : int * int -> System.ComponentModel.DataAnnotations.RangeAttribute
Public Sub New (minimum As Integer, maximum As Integer)

参数

minimum
Int32

指定数据字段值所允许的最小值。Specifies the minimum value allowed for the data field value.

maximum
Int32

指定数据字段值所允许的最大值。Specifies the maximum value allowed for the data field value.

示例

下面的示例演示如何使用 RangeAttribute 来指定整数数据字段的范围。The following example shows how to use the RangeAttribute to specify the range for an integer data field.

[Range(300, 3000)]
public object ListPrice;
<Range(300, 3000)> _
Public ListPrice As Object

适用于

RangeAttribute(Type, String, String)

使用指定的最小值和最大值以及特定类型初始化 RangeAttribute 类的一个新实例。Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values and the specific type.

public:
 RangeAttribute(Type ^ type, System::String ^ minimum, System::String ^ maximum);
public RangeAttribute (Type type, string minimum, string maximum);
new System.ComponentModel.DataAnnotations.RangeAttribute : Type * string * string -> System.ComponentModel.DataAnnotations.RangeAttribute
Public Sub New (type As Type, minimum As String, maximum As String)

参数

type
Type

指定要测试的对象的类型。Specifies the type of the object to test.

minimum
String

指定数据字段值所允许的最小值。Specifies the minimum value allowed for the data field value.

maximum
String

指定数据字段值所允许的最大值。Specifies the maximum value allowed for the data field value.

例外

typenulltype is null.

示例

下面的示例演示如何使用 RangeAttribute 方法指定字段的范围 DateTimeThe following example shows how to use the RangeAttribute method to specify the range for a DateTime field. 它还包括一个自定义错误消息,该消息演示如何使用方法的格式设置功能 FormatErrorMessageIt also includes a custom error message that shows how to use the formatting capabilities of the FormatErrorMessage method.

[Range(typeof(DateTime), "1/2/2004", "3/4/2004",
    ErrorMessage = "Value for {0} must be between {1} and {2}")]
public object SellEndDate;
<Range(GetType(DateTime), "1/2/2004", "3/4/2004", _
       ErrorMessage:="Value for {0} must be between {1} and {2}")> _
Public SellEndDate As Object

注解

要验证的对象必须实现 IComparable 接口。The object to validate must implement the IComparable interface.

适用于