Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlInt32.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 bool m_fNotNull;
16
17 private int m_value;
18
19 public static readonly SqlInt32 Null = new SqlInt32(fNull: true);
20
21 public static readonly SqlInt32 Zero = new SqlInt32(0);
22
23 public static readonly SqlInt32 MinValue = new SqlInt32(int.MinValue);
24
25 public static readonly SqlInt32 MaxValue = new SqlInt32(int.MaxValue);
26
27 public bool IsNull => !m_fNotNull;
28
29 public int Value
30 {
31 get
32 {
33 if (IsNull)
34 {
35 throw new SqlNullValueException();
36 }
37 return m_value;
38 }
39 }
40
41 private SqlInt32(bool fNull)
42 {
43 m_fNotNull = false;
44 m_value = 0;
45 }
46
47 public SqlInt32(int value)
48 {
49 m_value = value;
50 m_fNotNull = true;
51 }
52
53 public static implicit operator SqlInt32(int x)
54 {
55 return new SqlInt32(x);
56 }
57
58 public static explicit operator int(SqlInt32 x)
59 {
60 return x.Value;
61 }
62
63 public override string ToString()
64 {
65 if (!IsNull)
66 {
67 return m_value.ToString((IFormatProvider?)null);
68 }
70 }
71
72 public static SqlInt32 Parse(string s)
73 {
75 {
76 return Null;
77 }
78 return new SqlInt32(int.Parse(s, null));
79 }
80
81 public static SqlInt32 operator -(SqlInt32 x)
82 {
83 if (!x.IsNull)
84 {
85 return new SqlInt32(-x.m_value);
86 }
87 return Null;
88 }
89
90 public static SqlInt32 operator ~(SqlInt32 x)
91 {
92 if (!x.IsNull)
93 {
94 return new SqlInt32(~x.m_value);
95 }
96 return Null;
97 }
98
100 {
101 if (x.IsNull || y.IsNull)
102 {
103 return Null;
104 }
105 int num = x.m_value + y.m_value;
106 if (SameSignInt(x.m_value, y.m_value) && !SameSignInt(x.m_value, num))
107 {
109 }
110 return new SqlInt32(num);
111 }
112
114 {
115 if (x.IsNull || y.IsNull)
116 {
117 return Null;
118 }
119 int num = x.m_value - y.m_value;
120 if (!SameSignInt(x.m_value, y.m_value) && SameSignInt(y.m_value, num))
121 {
123 }
124 return new SqlInt32(num);
125 }
126
128 {
129 if (x.IsNull || y.IsNull)
130 {
131 return Null;
132 }
133 long num = (long)x.m_value * (long)y.m_value;
134 long num2 = num & int.MinValue;
135 if (num2 != 0L && num2 != int.MinValue)
136 {
138 }
139 return new SqlInt32((int)num);
140 }
141
143 {
144 if (x.IsNull || y.IsNull)
145 {
146 return Null;
147 }
148 if (y.m_value != 0)
149 {
150 if ((long)x.m_value == int.MinValue && y.m_value == -1)
151 {
153 }
154 return new SqlInt32(x.m_value / y.m_value);
155 }
157 }
158
160 {
161 if (x.IsNull || y.IsNull)
162 {
163 return Null;
164 }
165 if (y.m_value != 0)
166 {
167 if ((long)x.m_value == int.MinValue && y.m_value == -1)
168 {
170 }
171 return new SqlInt32(x.m_value % y.m_value);
172 }
174 }
175
177 {
178 if (!x.IsNull && !y.IsNull)
179 {
180 return new SqlInt32(x.m_value & y.m_value);
181 }
182 return Null;
183 }
184
186 {
187 if (!x.IsNull && !y.IsNull)
188 {
189 return new SqlInt32(x.m_value | y.m_value);
190 }
191 return Null;
192 }
193
195 {
196 if (!x.IsNull && !y.IsNull)
197 {
198 return new SqlInt32(x.m_value ^ y.m_value);
199 }
200 return Null;
201 }
202
203 public static explicit operator SqlInt32(SqlBoolean x)
204 {
205 if (!x.IsNull)
206 {
207 return new SqlInt32(x.ByteValue);
208 }
209 return Null;
210 }
211
212 public static implicit operator SqlInt32(SqlByte x)
213 {
214 if (!x.IsNull)
215 {
216 return new SqlInt32(x.Value);
217 }
218 return Null;
219 }
220
221 public static implicit operator SqlInt32(SqlInt16 x)
222 {
223 if (!x.IsNull)
224 {
225 return new SqlInt32(x.Value);
226 }
227 return Null;
228 }
229
230 public static explicit operator SqlInt32(SqlInt64 x)
231 {
232 if (x.IsNull)
233 {
234 return Null;
235 }
236 long value = x.Value;
237 if (value > int.MaxValue || value < int.MinValue)
238 {
240 }
241 return new SqlInt32((int)value);
242 }
243
244 public static explicit operator SqlInt32(SqlSingle x)
245 {
246 if (x.IsNull)
247 {
248 return Null;
249 }
250 float value = x.Value;
251 if (value > 2.1474836E+09f || value < -2.1474836E+09f)
252 {
254 }
255 return new SqlInt32((int)value);
256 }
257
258 public static explicit operator SqlInt32(SqlDouble x)
259 {
260 if (x.IsNull)
261 {
262 return Null;
263 }
264 double value = x.Value;
265 if (value > 2147483647.0 || value < -2147483648.0)
266 {
268 }
269 return new SqlInt32((int)value);
270 }
271
272 public static explicit operator SqlInt32(SqlMoney x)
273 {
274 if (!x.IsNull)
275 {
276 return new SqlInt32(x.ToInt32());
277 }
278 return Null;
279 }
280
281 public static explicit operator SqlInt32(SqlDecimal x)
282 {
283 if (x.IsNull)
284 {
285 return Null;
286 }
287 x.AdjustScale(-x.Scale, fRound: true);
288 long num = x._data1;
289 if (!x.IsPositive)
290 {
291 num = -num;
292 }
293 if (x._bLen > 1 || num > int.MaxValue || num < int.MinValue)
294 {
296 }
297 return new SqlInt32((int)num);
298 }
299
300 public static explicit operator SqlInt32(SqlString x)
301 {
302 if (!x.IsNull)
303 {
304 return new SqlInt32(int.Parse(x.Value, null));
305 }
306 return Null;
307 }
308
309 private static bool SameSignInt(int x, int y)
310 {
311 return ((x ^ y) & 0x80000000u) == 0;
312 }
313
315 {
316 if (!x.IsNull && !y.IsNull)
317 {
318 return new SqlBoolean(x.m_value == y.m_value);
319 }
320 return SqlBoolean.Null;
321 }
322
324 {
325 return !(x == y);
326 }
327
329 {
330 if (!x.IsNull && !y.IsNull)
331 {
332 return new SqlBoolean(x.m_value < y.m_value);
333 }
334 return SqlBoolean.Null;
335 }
336
338 {
339 if (!x.IsNull && !y.IsNull)
340 {
341 return new SqlBoolean(x.m_value > y.m_value);
342 }
343 return SqlBoolean.Null;
344 }
345
347 {
348 if (!x.IsNull && !y.IsNull)
349 {
350 return new SqlBoolean(x.m_value <= y.m_value);
351 }
352 return SqlBoolean.Null;
353 }
354
356 {
357 if (!x.IsNull && !y.IsNull)
358 {
359 return new SqlBoolean(x.m_value >= y.m_value);
360 }
361 return SqlBoolean.Null;
362 }
363
365 {
366 return ~x;
367 }
368
369 public static SqlInt32 Add(SqlInt32 x, SqlInt32 y)
370 {
371 return x + y;
372 }
373
374 public static SqlInt32 Subtract(SqlInt32 x, SqlInt32 y)
375 {
376 return x - y;
377 }
378
379 public static SqlInt32 Multiply(SqlInt32 x, SqlInt32 y)
380 {
381 return x * y;
382 }
383
384 public static SqlInt32 Divide(SqlInt32 x, SqlInt32 y)
385 {
386 return x / y;
387 }
388
389 public static SqlInt32 Mod(SqlInt32 x, SqlInt32 y)
390 {
391 return x % y;
392 }
393
394 public static SqlInt32 Modulus(SqlInt32 x, SqlInt32 y)
395 {
396 return x % y;
397 }
398
400 {
401 return x & y;
402 }
403
405 {
406 return x | y;
407 }
408
409 public static SqlInt32 Xor(SqlInt32 x, SqlInt32 y)
410 {
411 return x ^ y;
412 }
413
414 public static SqlBoolean Equals(SqlInt32 x, SqlInt32 y)
415 {
416 return x == y;
417 }
418
420 {
421 return x != y;
422 }
423
425 {
426 return x < y;
427 }
428
430 {
431 return x > y;
432 }
433
435 {
436 return x <= y;
437 }
438
440 {
441 return x >= y;
442 }
443
445 {
446 return (SqlBoolean)this;
447 }
448
450 {
451 return (SqlByte)this;
452 }
453
455 {
456 return this;
457 }
458
460 {
461 return (SqlInt16)this;
462 }
463
465 {
466 return this;
467 }
468
470 {
471 return this;
472 }
473
475 {
476 return this;
477 }
478
480 {
481 return this;
482 }
483
485 {
486 return (SqlString)this;
487 }
488
489 public int CompareTo(object? value)
490 {
492 {
493 return CompareTo(value2);
494 }
495 throw ADP.WrongType(value.GetType(), typeof(SqlInt32));
496 }
497
499 {
500 if (IsNull)
501 {
502 if (!value.IsNull)
503 {
504 return -1;
505 }
506 return 0;
507 }
508 if (value.IsNull)
509 {
510 return 1;
511 }
512 if (this < value)
513 {
514 return -1;
515 }
516 if (this > value)
517 {
518 return 1;
519 }
520 return 0;
521 }
522
523 public override bool Equals([NotNullWhen(true)] object? value)
524 {
525 if (!(value is SqlInt32 sqlInt))
526 {
527 return false;
528 }
529 if (sqlInt.IsNull || IsNull)
530 {
531 if (sqlInt.IsNull)
532 {
533 return IsNull;
534 }
535 return false;
536 }
537 return (this == sqlInt).Value;
538 }
539
540 public override int GetHashCode()
541 {
542 if (!IsNull)
543 {
544 return Value.GetHashCode();
545 }
546 return 0;
547 }
548
550 {
551 return null;
552 }
553
555 {
556 string attribute = reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
557 if (attribute != null && XmlConvert.ToBoolean(attribute))
558 {
559 reader.ReadElementString();
560 m_fNotNull = false;
561 }
562 else
563 {
565 m_fNotNull = true;
566 }
567 }
568
570 {
571 if (IsNull)
572 {
573 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
574 }
575 else
576 {
577 writer.WriteString(XmlConvert.ToString(m_value));
578 }
579 }
580
582 {
583 return new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
584 }
585}
static Exception WrongType(Type got, Type expected)
Definition ADP.cs:174
static string ConversionOverflowMessage
static bool ToBoolean(string s)
static int ToInt32(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
void AdjustScale(int digits, bool fRound)
static SqlInt32 Divide(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:384
static SqlBoolean operator<=(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:346
static SqlInt32 Xor(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:409
static SqlInt32 operator~(SqlInt32 x)
Definition SqlInt32.cs:90
static SqlBoolean LessThan(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:424
static SqlInt32 operator%(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:159
override bool Equals([NotNullWhen(true)] object? value)
Definition SqlInt32.cs:523
static SqlBoolean operator>=(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:355
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
Definition SqlInt32.cs:581
static SqlInt32 Add(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:369
int CompareTo(SqlInt32 value)
Definition SqlInt32.cs:498
static readonly SqlInt32 MaxValue
Definition SqlInt32.cs:25
static bool SameSignInt(int x, int y)
Definition SqlInt32.cs:309
static SqlInt32 BitwiseOr(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:404
static SqlInt32 operator+(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:99
static SqlInt32 Parse(string s)
Definition SqlInt32.cs:72
static SqlInt32 operator^(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:194
static SqlInt32 operator&(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:176
int CompareTo(object? value)
Definition SqlInt32.cs:489
static SqlInt32 operator/(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:142
static readonly SqlInt32 Null
Definition SqlInt32.cs:19
static SqlInt32 BitwiseAnd(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:399
static SqlBoolean GreaterThanOrEqual(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:439
override string ToString()
Definition SqlInt32.cs:63
static SqlBoolean operator==(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:314
static SqlBoolean operator>(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:337
static SqlInt32 Multiply(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:379
static SqlBoolean GreaterThan(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:429
static SqlInt32 operator|(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:185
static SqlInt32 operator*(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:127
static SqlBoolean operator!=(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:323
static SqlInt32 Subtract(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:374
static SqlBoolean NotEquals(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:419
static SqlInt32 OnesComplement(SqlInt32 x)
Definition SqlInt32.cs:364
static SqlBoolean LessThanOrEqual(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:434
static SqlInt32 operator-(SqlInt32 x)
Definition SqlInt32.cs:81
static SqlInt32 Modulus(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:394
static SqlInt32 Mod(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:389
static SqlBoolean operator<(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:328
static readonly SqlInt32 Zero
Definition SqlInt32.cs:21
static SqlBoolean Equals(SqlInt32 x, SqlInt32 y)
Definition SqlInt32.cs:414
static readonly SqlInt32 MinValue
Definition SqlInt32.cs:23