RangeAttribute 构造函数

定义

初始化 RangeAttribute 类的新实例。

重载

名称 说明
RangeAttribute(Double, Double)

使用指定的最小值和最大值初始化类的新实例 RangeAttribute

RangeAttribute(Int32, Int32)

使用指定的最小值和最大值初始化类的新实例 RangeAttribute

RangeAttribute(Type, String, String)

使用指定的最小值和最大值和特定类型初始化类的新实例 RangeAttribute

RangeAttribute(Double, Double)

Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs

使用指定的最小值和最大值初始化类的新实例 RangeAttribute

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

指定数据字段值允许的最小值。

maximum
Double

指定数据字段值允许的最大值。

适用于

RangeAttribute(Int32, Int32)

Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs

使用指定的最小值和最大值初始化类的新实例 RangeAttribute

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

指定数据字段值允许的最小值。

maximum
Int32

指定数据字段值允许的最大值。

示例

以下示例演示如何使用 RangeAttribute 指定整数数据字段的范围。

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

适用于

RangeAttribute(Type, String, String)

Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs

使用指定的最小值和最大值和特定类型初始化类的新实例 RangeAttribute

public:
 RangeAttribute(Type ^ type, System::String ^ minimum, System::String ^ maximum);
public RangeAttribute(Type type, string minimum, string maximum);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
public RangeAttribute(Type type, string minimum, string maximum);
new System.ComponentModel.DataAnnotations.RangeAttribute : Type * string * string -> System.ComponentModel.DataAnnotations.RangeAttribute
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")>]
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

指定要测试的对象的类型。

minimum
String

指定数据字段值允许的最小值。

maximum
String

指定数据字段值允许的最大值。

属性

例外

typenull

示例

以下示例演示如何使用 RangeAttribute 该方法指定字段的范围 DateTime 。 它还包含一条自定义错误消息,其中显示了如何使用该方法的格式 FormatErrorMessage 设置功能。

[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 接口。

适用于