Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlBoolean.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 byte m_value;
16
17 public static readonly SqlBoolean True = new SqlBoolean(value: true);
18
19 public static readonly SqlBoolean False = new SqlBoolean(value: false);
20
21 public static readonly SqlBoolean Null = new SqlBoolean(0, fNull: true);
22
23 public static readonly SqlBoolean Zero = new SqlBoolean(0);
24
25 public static readonly SqlBoolean One = new SqlBoolean(1);
26
27 public bool IsNull => m_value == 0;
28
29 public bool Value => m_value switch
30 {
31 2 => true,
32 1 => false,
33 _ => throw new SqlNullValueException(),
34 };
35
36 public bool IsTrue => m_value == 2;
37
38 public bool IsFalse => m_value == 1;
39
40 public byte ByteValue
41 {
42 get
43 {
44 if (!IsNull)
45 {
46 if (m_value != 2)
47 {
48 return 0;
49 }
50 return 1;
51 }
52 throw new SqlNullValueException();
53 }
54 }
55
56 public SqlBoolean(bool value)
57 {
58 m_value = (byte)((!value) ? 1 : 2);
59 }
60
61 public SqlBoolean(int value)
63 {
64 }
65
66 private SqlBoolean(int value, bool fNull)
67 {
68 if (fNull)
69 {
70 m_value = 0;
71 }
72 else
73 {
74 m_value = (byte)((value == 0) ? 1 : 2);
75 }
76 }
77
78 public static implicit operator SqlBoolean(bool x)
79 {
80 return new SqlBoolean(x);
81 }
82
83 public static explicit operator bool(SqlBoolean x)
84 {
85 return x.Value;
86 }
87
89 {
90 return x.m_value switch
91 {
92 2 => False,
93 1 => True,
94 _ => Null,
95 };
96 }
97
98 public static bool operator true(SqlBoolean x)
99 {
100 return x.IsTrue;
101 }
102
103 public static bool operator false(SqlBoolean x)
104 {
105 return x.IsFalse;
106 }
107
109 {
110 if (x.m_value == 1 || y.m_value == 1)
111 {
112 return False;
113 }
114 if (x.m_value == 2 && y.m_value == 2)
115 {
116 return True;
117 }
118 return Null;
119 }
120
122 {
123 if (x.m_value == 2 || y.m_value == 2)
124 {
125 return True;
126 }
127 if (x.m_value == 1 && y.m_value == 1)
128 {
129 return False;
130 }
131 return Null;
132 }
133
134 public override string ToString()
135 {
136 if (!IsNull)
137 {
138 return Value.ToString();
139 }
140 return SQLResource.NullString;
141 }
142
143 public static SqlBoolean Parse(string s)
144 {
145 if (s == null)
146 {
147 return new SqlBoolean(bool.Parse(s));
148 }
149 if (s == SQLResource.NullString)
150 {
151 return Null;
152 }
153 s = s.TrimStart();
154 char c = s[0];
155 if (char.IsNumber(c) || '-' == c || '+' == c)
156 {
157 return new SqlBoolean(int.Parse(s, null));
158 }
159 return new SqlBoolean(bool.Parse(s));
160 }
161
163 {
164 return !x;
165 }
166
168 {
169 if (!x.IsNull && !y.IsNull)
170 {
171 return new SqlBoolean(x.m_value != y.m_value);
172 }
173 return Null;
174 }
175
176 public static explicit operator SqlBoolean(SqlByte x)
177 {
178 if (!x.IsNull)
179 {
180 return new SqlBoolean(x.Value != 0);
181 }
182 return Null;
183 }
184
185 public static explicit operator SqlBoolean(SqlInt16 x)
186 {
187 if (!x.IsNull)
188 {
189 return new SqlBoolean(x.Value != 0);
190 }
191 return Null;
192 }
193
194 public static explicit operator SqlBoolean(SqlInt32 x)
195 {
196 if (!x.IsNull)
197 {
198 return new SqlBoolean(x.Value != 0);
199 }
200 return Null;
201 }
202
203 public static explicit operator SqlBoolean(SqlInt64 x)
204 {
205 if (!x.IsNull)
206 {
207 return new SqlBoolean(x.Value != 0);
208 }
209 return Null;
210 }
211
212 public static explicit operator SqlBoolean(SqlDouble x)
213 {
214 if (!x.IsNull)
215 {
216 return new SqlBoolean(x.Value != 0.0);
217 }
218 return Null;
219 }
220
221 public static explicit operator SqlBoolean(SqlSingle x)
222 {
223 if (!x.IsNull)
224 {
225 return new SqlBoolean((double)x.Value != 0.0);
226 }
227 return Null;
228 }
229
230 public static explicit operator SqlBoolean(SqlMoney x)
231 {
232 if (!x.IsNull)
233 {
234 return x != SqlMoney.Zero;
235 }
236 return Null;
237 }
238
239 public static explicit operator SqlBoolean(SqlDecimal x)
240 {
241 if (!x.IsNull)
242 {
243 return new SqlBoolean(x._data1 != 0 || x._data2 != 0 || x._data3 != 0 || x._data4 != 0);
244 }
245 return Null;
246 }
247
248 public static explicit operator SqlBoolean(SqlString x)
249 {
250 if (!x.IsNull)
251 {
252 return Parse(x.Value);
253 }
254 return Null;
255 }
256
258 {
259 if (!x.IsNull && !y.IsNull)
260 {
261 return new SqlBoolean(x.m_value == y.m_value);
262 }
263 return Null;
264 }
265
267 {
268 return !(x == y);
269 }
270
272 {
273 if (!x.IsNull && !y.IsNull)
274 {
275 return new SqlBoolean(x.m_value < y.m_value);
276 }
277 return Null;
278 }
279
281 {
282 if (!x.IsNull && !y.IsNull)
283 {
284 return new SqlBoolean(x.m_value > y.m_value);
285 }
286 return Null;
287 }
288
290 {
291 if (!x.IsNull && !y.IsNull)
292 {
293 return new SqlBoolean(x.m_value <= y.m_value);
294 }
295 return Null;
296 }
297
299 {
300 if (!x.IsNull && !y.IsNull)
301 {
302 return new SqlBoolean(x.m_value >= y.m_value);
303 }
304 return Null;
305 }
306
308 {
309 return ~x;
310 }
311
313 {
314 return x & y;
315 }
316
317 public static SqlBoolean Or(SqlBoolean x, SqlBoolean y)
318 {
319 return x | y;
320 }
321
323 {
324 return x ^ y;
325 }
326
328 {
329 return x == y;
330 }
331
333 {
334 return x != y;
335 }
336
338 {
339 return x > y;
340 }
341
343 {
344 return x < y;
345 }
346
348 {
349 return x >= y;
350 }
351
353 {
354 return x <= y;
355 }
356
358 {
359 return (SqlByte)this;
360 }
361
363 {
364 return (SqlDouble)this;
365 }
366
368 {
369 return (SqlInt16)this;
370 }
371
373 {
374 return (SqlInt32)this;
375 }
376
378 {
379 return (SqlInt64)this;
380 }
381
383 {
384 return (SqlMoney)this;
385 }
386
388 {
389 return (SqlDecimal)this;
390 }
391
393 {
394 return (SqlSingle)this;
395 }
396
398 {
399 return (SqlString)this;
400 }
401
402 public int CompareTo(object? value)
403 {
405 {
406 return CompareTo(value2);
407 }
408 throw ADP.WrongType(value.GetType(), typeof(SqlBoolean));
409 }
410
412 {
413 if (IsNull)
414 {
415 if (!value.IsNull)
416 {
417 return -1;
418 }
419 return 0;
420 }
421 if (value.IsNull)
422 {
423 return 1;
424 }
425 if (ByteValue < value.ByteValue)
426 {
427 return -1;
428 }
429 if (ByteValue > value.ByteValue)
430 {
431 return 1;
432 }
433 return 0;
434 }
435
436 public override bool Equals([NotNullWhen(true)] object? value)
437 {
439 {
440 return false;
441 }
442 if (sqlBoolean.IsNull || IsNull)
443 {
444 if (sqlBoolean.IsNull)
445 {
446 return IsNull;
447 }
448 return false;
449 }
450 return (this == sqlBoolean).Value;
451 }
452
453 public override int GetHashCode()
454 {
455 if (!IsNull)
456 {
457 return Value.GetHashCode();
458 }
459 return 0;
460 }
461
463 {
464 return null;
465 }
466
468 {
469 string attribute = reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
470 if (attribute != null && XmlConvert.ToBoolean(attribute))
471 {
472 reader.ReadElementString();
473 m_value = 0;
474 }
475 else
476 {
477 m_value = (byte)((!XmlConvert.ToBoolean(reader.ReadElementString())) ? 1 : 2);
478 }
479 }
480
482 {
483 if (IsNull)
484 {
485 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
486 }
487 else
488 {
489 writer.WriteString((m_value == 2) ? "true" : "false");
490 }
491 }
492
494 {
495 return new XmlQualifiedName("boolean", "http://www.w3.org/2001/XMLSchema");
496 }
497}
static Exception WrongType(Type got, Type expected)
Definition ADP.cs:174
static bool ToBoolean(string s)
string? GetAttribute(string name)
virtual string ReadElementString()
Definition XmlReader.cs:667
static SqlBoolean LessThanOrEquals(SqlBoolean x, SqlBoolean y)
static SqlBoolean Xor(SqlBoolean x, SqlBoolean y)
static SqlBoolean operator<(SqlBoolean x, SqlBoolean y)
static readonly SqlBoolean True
Definition SqlBoolean.cs:17
static SqlBoolean operator|(SqlBoolean x, SqlBoolean y)
int CompareTo(SqlBoolean value)
static SqlBoolean GreaterThanOrEquals(SqlBoolean x, SqlBoolean y)
static SqlBoolean operator>(SqlBoolean x, SqlBoolean y)
override bool Equals([NotNullWhen(true)] object? value)
static SqlBoolean OnesComplement(SqlBoolean x)
static SqlBoolean NotEquals(SqlBoolean x, SqlBoolean y)
int CompareTo(object? value)
SqlBoolean(int value, bool fNull)
Definition SqlBoolean.cs:66
static SqlBoolean operator&(SqlBoolean x, SqlBoolean y)
static readonly SqlBoolean Null
Definition SqlBoolean.cs:21
static SqlBoolean And(SqlBoolean x, SqlBoolean y)
static SqlBoolean LessThan(SqlBoolean x, SqlBoolean y)
static SqlBoolean Or(SqlBoolean x, SqlBoolean y)
static SqlBoolean operator<=(SqlBoolean x, SqlBoolean y)
static SqlBoolean operator!=(SqlBoolean x, SqlBoolean y)
static SqlBoolean GreaterThan(SqlBoolean x, SqlBoolean y)
static readonly SqlBoolean Zero
Definition SqlBoolean.cs:23
static SqlBoolean operator>=(SqlBoolean x, SqlBoolean y)
static SqlBoolean operator^(SqlBoolean x, SqlBoolean y)
static readonly SqlBoolean One
Definition SqlBoolean.cs:25
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
static SqlBoolean Parse(string s)
static SqlBoolean operator~(SqlBoolean x)
static readonly SqlBoolean False
Definition SqlBoolean.cs:19
static SqlBoolean Equals(SqlBoolean x, SqlBoolean y)
static SqlBoolean operator==(SqlBoolean x, SqlBoolean y)
static SqlBoolean operator!(SqlBoolean x)
Definition SqlBoolean.cs:88
static readonly SqlMoney Zero
Definition SqlMoney.cs:19