disable broken tests on net_4_0
[mcs.git] / docs / ecma334 / 18.4.1.xml
blobebf99931ca1ad7656956fac897305d8c5af2fa36
1 <?xml version="1.0"?>
2 <clause number="18.4.1" title="Database integer type" informative="true">
3   <paragraph>The DBInt struct below implements an integer type that can represent the complete set of values of the <keyword>int</keyword> type, plus an additional state that indicates an unknown value. A type with these characteristics is commonly used in databases. <code_example><![CDATA[
4 using System;  
5 public struct DBInt  
6 {  
7    // The Null member represents an unknown DBInt value.  
8    public static readonly DBInt Null = new DBInt();  
9    // When the defined field is true, this DBInt represents a known value  
10    // which is stored in the value field. When the defined field is false,  
11    
12    // this DBInt represents an unknown value, and the value field is 0.  
13    int value;  
14    bool defined;  
15    // Private instance constructor. Creates a DBInt with a known value.  
16    DBInt(int value) {  
17       this.value = value;  
18       this.defined = true;  
19    }  
20    // The IsNull property is true if this DBInt represents an unknown value.  
21    
22    public bool IsNull { get { return !defined; } }  
23    // The Value property is the known value of this DBInt, or 0 if this  
24    // DBInt represents an unknown value.  
25    public int Value { get { return value; } }  
26    // Implicit conversion from int to DBInt.  
27    public static implicit operator DBInt(int x) {  
28       return new DBInt(x);  
29    }  
30    // Explicit conversion from DBInt to int. Throws an exception if the  
31    // given DBInt represents an unknown value.  
32    public static explicit operator int(DBInt x) {  
33       if (!x.defined) throw new InvalidOperationException();  
34       return x.value;  
35    }  
36    public static DBInt operator +(DBInt x) {  
37       return x;  
38    }  
39    public static DBInt operator -(DBInt x) {  
40       return x.defined? -x.value: Null;  
41    }  
42    public static DBInt operator +(DBInt x, DBInt y) {  
43       return x.defined && y.defined? x.value + y.value: Null;  
44    }  
45    public static DBInt operator -(DBInt x, DBInt y) {  
46       return x.defined && y.defined? x.value - y.value: Null;  
47    }  
48    public static DBInt operator *(DBInt x, DBInt y) {  
49       return x.defined && y.defined? x.value * y.value: Null;  
50    }  
51    public static DBInt operator /(DBInt x, DBInt y) {  
52       return x.defined && y.defined? x.value / y.value: Null;  
53    }  
54    public static DBInt operator %(DBInt x, DBInt y) {  
55       return x.defined && y.defined? x.value % y.value: Null;  
56    }  
57    public static DBBool operator ==(DBInt x, DBInt y) {  
58       return x.defined && y.defined? x.value == y.value: DBBool.Null;  
59    }  
60    public static DBBool operator !=(DBInt x, DBInt y) {  
61       return x.defined && y.defined? x.value != y.value: DBBool.Null;  
62    }  
63    public static DBBool operator >(DBInt x, DBInt y) {  
64       return x.defined && y.defined? x.value > y.value: DBBool.Null;  
65    }  
66    public static DBBool operator <(DBInt x, DBInt y) {  
67       return x.defined && y.defined? x.value < y.value: DBBool.Null;  
68    }  
69    public static DBBool operator >=(DBInt x, DBInt y) {  
70       return x.defined && y.defined? x.value >= y.value: DBBool.Null;  
71    }  
72    public static DBBool operator <=(DBInt x, DBInt y) {  
73       return x.defined && y.defined? x.value <= y.value: DBBool.Null;  
74    }  
75 }  
76 ]]></code_example></paragraph>
77 </clause>