-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
IntegerValidatorAttribute.cs
40 lines (33 loc) · 1.14 KB
/
IntegerValidatorAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Configuration
{
[AttributeUsage(AttributeTargets.Property)]
public sealed class IntegerValidatorAttribute : ConfigurationValidatorAttribute
{
private int _max = int.MaxValue;
private int _min = int.MinValue;
public override ConfigurationValidatorBase ValidatorInstance => new IntegerValidator(_min, _max, ExcludeRange);
public int MinValue
{
get { return _min; }
set
{
if (_max < value)
throw new ArgumentOutOfRangeException(nameof(value), SR.Validator_min_greater_than_max);
_min = value;
}
}
public int MaxValue
{
get { return _max; }
set
{
if (_min > value)
throw new ArgumentOutOfRangeException(nameof(value), SR.Validator_min_greater_than_max);
_max = value;
}
}
public bool ExcludeRange { get; set; }
}
}