Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlGuid.cs
Go to the documentation of this file.
4using System.Xml;
7
9
11[XmlSchemaProvider("GetXsdType")]
12[TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
14{
15 private static readonly int[] s_rgiGuidOrder = new int[16]
16 {
17 10, 11, 12, 13, 14, 15, 8, 9, 6, 7,
18 4, 5, 0, 1, 2, 3
19 };
20
21 private byte[] m_value;
22
23 public static readonly SqlGuid Null = new SqlGuid(fNull: true);
24
25 public bool IsNull => m_value == null;
26
27 public Guid Value
28 {
29 get
30 {
31 if (m_value == null)
32 {
33 throw new SqlNullValueException();
34 }
35 return new Guid(m_value);
36 }
37 }
38
39 private SqlGuid(bool fNull)
40 {
41 m_value = null;
42 }
43
44 public SqlGuid(byte[] value)
45 {
46 if (value == null || value.Length != 16)
47 {
49 }
50 m_value = new byte[16];
51 value.CopyTo(m_value, 0);
52 }
53
54 public SqlGuid(string s)
55 {
56 m_value = new Guid(s).ToByteArray();
57 }
58
59 public SqlGuid(Guid g)
60 {
61 m_value = g.ToByteArray();
62 }
63
64 public SqlGuid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)
65 : this(new Guid(a, b, c, d, e, f, g, h, i, j, k))
66 {
67 }
68
69 public static implicit operator SqlGuid(Guid x)
70 {
71 return new SqlGuid(x);
72 }
73
74 public static explicit operator Guid(SqlGuid x)
75 {
76 return x.Value;
77 }
78
79 public byte[]? ToByteArray()
80 {
81 byte[] array = new byte[16];
82 m_value.CopyTo(array, 0);
83 return array;
84 }
85
86 public override string ToString()
87 {
88 if (m_value == null)
89 {
91 }
92 return new Guid(m_value).ToString();
93 }
94
95 public static SqlGuid Parse(string s)
96 {
98 {
99 return Null;
100 }
101 return new SqlGuid(s);
102 }
103
104 private static EComparison Compare(SqlGuid x, SqlGuid y)
105 {
106 for (int i = 0; i < 16; i++)
107 {
108 byte b = x.m_value[s_rgiGuidOrder[i]];
109 byte b2 = y.m_value[s_rgiGuidOrder[i]];
110 if (b != b2)
111 {
112 if (b >= b2)
113 {
114 return EComparison.GT;
115 }
116 return EComparison.LT;
117 }
118 }
119 return EComparison.EQ;
120 }
121
122 public static explicit operator SqlGuid(SqlString x)
123 {
124 if (!x.IsNull)
125 {
126 return new SqlGuid(x.Value);
127 }
128 return Null;
129 }
130
131 public static explicit operator SqlGuid(SqlBinary x)
132 {
133 if (!x.IsNull)
134 {
135 return new SqlGuid(x.Value);
136 }
137 return Null;
138 }
139
141 {
142 if (!x.IsNull && !y.IsNull)
143 {
144 return new SqlBoolean(Compare(x, y) == EComparison.EQ);
145 }
146 return SqlBoolean.Null;
147 }
148
150 {
151 return !(x == y);
152 }
153
155 {
156 if (!x.IsNull && !y.IsNull)
157 {
158 return new SqlBoolean(Compare(x, y) == EComparison.LT);
159 }
160 return SqlBoolean.Null;
161 }
162
164 {
165 if (!x.IsNull && !y.IsNull)
166 {
167 return new SqlBoolean(Compare(x, y) == EComparison.GT);
168 }
169 return SqlBoolean.Null;
170 }
171
173 {
174 if (x.IsNull || y.IsNull)
175 {
176 return SqlBoolean.Null;
177 }
179 return new SqlBoolean(eComparison == EComparison.LT || eComparison == EComparison.EQ);
180 }
181
183 {
184 if (x.IsNull || y.IsNull)
185 {
186 return SqlBoolean.Null;
187 }
189 return new SqlBoolean(eComparison == EComparison.GT || eComparison == EComparison.EQ);
190 }
191
192 public static SqlBoolean Equals(SqlGuid x, SqlGuid y)
193 {
194 return x == y;
195 }
196
198 {
199 return x != y;
200 }
201
202 public static SqlBoolean LessThan(SqlGuid x, SqlGuid y)
203 {
204 return x < y;
205 }
206
208 {
209 return x > y;
210 }
211
213 {
214 return x <= y;
215 }
216
218 {
219 return x >= y;
220 }
221
223 {
224 return (SqlString)this;
225 }
226
228 {
229 return (SqlBinary)this;
230 }
231
232 public int CompareTo(object? value)
233 {
235 {
236 return CompareTo(value2);
237 }
238 throw ADP.WrongType(value.GetType(), typeof(SqlGuid));
239 }
240
242 {
243 if (IsNull)
244 {
245 if (!value.IsNull)
246 {
247 return -1;
248 }
249 return 0;
250 }
251 if (value.IsNull)
252 {
253 return 1;
254 }
255 if (this < value)
256 {
257 return -1;
258 }
259 if (this > value)
260 {
261 return 1;
262 }
263 return 0;
264 }
265
266 public override bool Equals([NotNullWhen(true)] object? value)
267 {
268 if (!(value is SqlGuid sqlGuid))
269 {
270 return false;
271 }
272 if (sqlGuid.IsNull || IsNull)
273 {
274 if (sqlGuid.IsNull)
275 {
276 return IsNull;
277 }
278 return false;
279 }
280 return (this == sqlGuid).Value;
281 }
282
283 public override int GetHashCode()
284 {
285 if (!IsNull)
286 {
287 return Value.GetHashCode();
288 }
289 return 0;
290 }
291
293 {
294 return null;
295 }
296
298 {
299 string attribute = reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
300 if (attribute != null && XmlConvert.ToBoolean(attribute))
301 {
302 reader.ReadElementString();
303 m_value = null;
304 }
305 else
306 {
307 m_value = new Guid(reader.ReadElementString()).ToByteArray();
308 }
309 }
310
312 {
313 if (m_value == null)
314 {
315 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
316 }
317 else
318 {
319 writer.WriteString(XmlConvert.ToString(new Guid(m_value)));
320 }
321 }
322
324 {
325 return new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
326 }
327}
static Exception WrongType(Type got, Type expected)
Definition ADP.cs:174
static bool ToBoolean(string s)
static string ToString(bool value)
string? GetAttribute(string name)
virtual string ReadElementString()
Definition XmlReader.cs:667
static readonly SqlBoolean Null
Definition SqlBoolean.cs:21
static SqlBoolean operator!=(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:149
static SqlBoolean operator>=(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:182
static SqlBoolean Equals(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:192
static SqlBoolean operator>(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:163
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
Definition SqlGuid.cs:323
static readonly int[] s_rgiGuidOrder
Definition SqlGuid.cs:15
static readonly SqlGuid Null
Definition SqlGuid.cs:23
static SqlBoolean NotEquals(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:197
int CompareTo(SqlGuid value)
Definition SqlGuid.cs:241
static SqlBoolean GreaterThan(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:207
static SqlBoolean operator==(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:140
static SqlBoolean operator<(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:154
override int GetHashCode()
Definition SqlGuid.cs:283
override string ToString()
Definition SqlGuid.cs:86
SqlGuid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)
Definition SqlGuid.cs:64
override bool Equals([NotNullWhen(true)] object? value)
Definition SqlGuid.cs:266
static SqlBoolean LessThanOrEqual(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:212
static SqlBoolean LessThan(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:202
static SqlGuid Parse(string s)
Definition SqlGuid.cs:95
static SqlBoolean GreaterThanOrEqual(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:217
static EComparison Compare(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:104
static SqlBoolean operator<=(SqlGuid x, SqlGuid y)
Definition SqlGuid.cs:172
int CompareTo(object? value)
Definition SqlGuid.cs:232
byte[] ToByteArray()
Definition Guid.cs:681
override int GetHashCode()
Definition Guid.cs:700