Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Data / System / Data / Range.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="Range.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">[....]</owner>
6 // <owner current="true" primary="false">[....]</owner>
7 // <owner current="false" primary="false">[....]</owner>
8 //------------------------------------------------------------------------------
9
10 namespace System.Data {
11     using System;
12
13     internal struct Range {
14
15         private int min;
16         private int max;
17         private bool isNotNull; // zero bit pattern represents null
18
19         public Range(int min, int max) {
20             if (min > max) {
21                 throw ExceptionBuilder.RangeArgument(min, max);
22             }
23             this.min = min;
24             this.max = max;
25             isNotNull = true;
26         }
27
28         public int Count {
29             get {
30                 if (IsNull)
31                     return 0;
32                 return max - min + 1;
33             }
34         }
35
36         public bool IsNull {
37             get {
38                 return !isNotNull;
39             }
40         }
41
42         public int Max {
43             get {
44                 CheckNull();
45                 return max;
46             }
47         }
48
49         public int Min {
50             get {
51                 CheckNull();
52                 return min;
53             }
54         }
55
56         internal void CheckNull() {
57             if (this.IsNull) {
58                 throw ExceptionBuilder.NullRange();
59             }
60         }
61     }
62 }