Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Nullable.cs
Go to the documentation of this file.
4
5namespace System;
6
9[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
10public struct Nullable<T> where T : struct
11{
12 private readonly bool hasValue;
13
14 internal T value;
15
16 public readonly bool HasValue
17 {
19 get
20 {
21 return hasValue;
22 }
23 }
24
25 public readonly T Value
26 {
27 get
28 {
29 if (!hasValue)
30 {
32 }
33 return value;
34 }
35 }
36
38 public Nullable(T value)
39 {
40 this.value = value;
41 hasValue = true;
42 }
43
45 public readonly T GetValueOrDefault()
46 {
47 return value;
48 }
49
51 public readonly T GetValueOrDefault(T defaultValue)
52 {
53 if (!hasValue)
54 {
55 return defaultValue;
56 }
57 return value;
58 }
59
60 public override bool Equals(object? other)
61 {
62 if (!hasValue)
63 {
64 return other == null;
65 }
66 if (other == null)
67 {
68 return false;
69 }
70 return value.Equals(other);
71 }
72
73 public override int GetHashCode()
74 {
75 if (!hasValue)
76 {
77 return 0;
78 }
79 return value.GetHashCode();
80 }
81
82 public override string? ToString()
83 {
84 if (!hasValue)
85 {
86 return "";
87 }
88 return value.ToString();
89 }
90
92 public static implicit operator T?(T value)
93 {
94 return value;
95 }
96
98 public static explicit operator T(T? value)
99 {
100 return value.Value;
101 }
102}
103public static class Nullable
104{
105 public static int Compare<T>(T? n1, T? n2) where T : struct
106 {
107 if (n1.HasValue)
108 {
109 if (n2.HasValue)
110 {
111 return Comparer<T>.Default.Compare(n1.value, n2.value);
112 }
113 return 1;
114 }
115 if (n2.HasValue)
116 {
117 return -1;
118 }
119 return 0;
120 }
121
122 public static bool Equals<T>(T? n1, T? n2) where T : struct
123 {
124 if (n1.HasValue)
125 {
126 if (n2.HasValue)
127 {
128 return EqualityComparer<T>.Default.Equals(n1.value, n2.value);
129 }
130 return false;
131 }
132 if (n2.HasValue)
133 {
134 return false;
135 }
136 return true;
137 }
138
140 {
141 if ((object)nullableType == null)
142 {
143 throw new ArgumentNullException("nullableType");
144 }
145 if (nullableType.IsGenericType && !nullableType.IsGenericTypeDefinition)
146 {
147 Type genericTypeDefinition = nullableType.GetGenericTypeDefinition();
149 {
150 return nullableType.GetGenericArguments()[0];
151 }
152 }
153 return null;
154 }
155}
static void ThrowInvalidOperationException_InvalidOperation_NoValue()
readonly T Value
Definition Nullable.cs:26
override? string ToString()
Definition Nullable.cs:82
static bool Equals< T >(T? n1, T? n2)
Definition Nullable.cs:122
static int Compare< T >(T? n1, T? n2)
Definition Nullable.cs:105
override bool Equals(object? other)
Definition Nullable.cs:60
Nullable(T value)
Definition Nullable.cs:38
static ? Type GetUnderlyingType(Type nullableType)
Definition Nullable.cs:139
readonly bool hasValue
Definition Nullable.cs:12
readonly bool HasValue
Definition Nullable.cs:17
readonly T GetValueOrDefault(T defaultValue)
Definition Nullable.cs:51
override int GetHashCode()
Definition Nullable.cs:73
readonly T GetValueOrDefault()
Definition Nullable.cs:45