2004-04-08 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / corlib / System / Nullable.cs
1 //
2 // System.Nullable
3 //
4 // Martin Baulig (martin@ximian.com)
5 //
6 // (C) 2004 Novell, Inc.
7 //
8
9 using System.Reflection;
10 #if GENERICS
11 using System.Collections.Generic;
12 #endif
13 using System.Runtime.CompilerServices;
14
15 #if GENERICS
16 namespace System
17 {
18         [CLSCompliant(false)]
19         public struct Nullable<T>
20         {
21                 T value;
22                 bool has_value;
23
24                 public Nullable (T value)
25                 {
26                         this.value = value;
27                         this.has_value = true;
28                 }
29
30                 public bool HasValue {
31                         get { return has_value; }
32                 }
33
34                 public T Value {
35                         get { return value; }
36                 }
37
38                 public T GetValueOrDefault ()
39                 {
40                         if (has_value)
41                                 return value;
42                         return default (T);
43                 }
44
45                 public T GetValueOrDefault (T def_value)
46                 {
47                         if (has_value)
48                                 return value;
49                         else
50                                 return def_value;
51                 }
52         }
53 }
54 #endif