Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlSingle.cs
Go to the documentation of this file.
4using System.Xml;
7
9
10[XmlSchemaProvider("GetXsdType")]
12{
13 private bool _fNotNull;
14
15 private float _value;
16
17 public static readonly SqlSingle Null = new SqlSingle(fNull: true);
18
19 public static readonly SqlSingle Zero = new SqlSingle(0f);
20
21 public static readonly SqlSingle MinValue = new SqlSingle(float.MinValue);
22
23 public static readonly SqlSingle MaxValue = new SqlSingle(float.MaxValue);
24
25 public bool IsNull => !_fNotNull;
26
27 public float Value
28 {
29 get
30 {
31 if (_fNotNull)
32 {
33 return _value;
34 }
35 throw new SqlNullValueException();
36 }
37 }
38
39 private SqlSingle(bool fNull)
40 {
41 _fNotNull = false;
42 _value = 0f;
43 }
44
45 public SqlSingle(float value)
46 {
47 if (!float.IsFinite(value))
48 {
50 }
51 _fNotNull = true;
52 _value = value;
53 }
54
55 public SqlSingle(double value)
56 : this((float)value)
57 {
58 }
59
60 public static implicit operator SqlSingle(float x)
61 {
62 return new SqlSingle(x);
63 }
64
65 public static explicit operator float(SqlSingle x)
66 {
67 return x.Value;
68 }
69
70 public override string ToString()
71 {
72 if (!IsNull)
73 {
74 return _value.ToString((IFormatProvider?)null);
75 }
77 }
78
79 public static SqlSingle Parse(string s)
80 {
82 {
83 return Null;
84 }
85 return new SqlSingle(float.Parse(s, CultureInfo.InvariantCulture));
86 }
87
89 {
90 if (!x.IsNull)
91 {
92 return new SqlSingle(0f - x._value);
93 }
94 return Null;
95 }
96
98 {
99 if (x.IsNull || y.IsNull)
100 {
101 return Null;
102 }
103 float num = x._value + y._value;
104 if (float.IsInfinity(num))
105 {
107 }
108 return new SqlSingle(num);
109 }
110
112 {
113 if (x.IsNull || y.IsNull)
114 {
115 return Null;
116 }
117 float num = x._value - y._value;
118 if (float.IsInfinity(num))
119 {
121 }
122 return new SqlSingle(num);
123 }
124
126 {
127 if (x.IsNull || y.IsNull)
128 {
129 return Null;
130 }
131 float num = x._value * y._value;
132 if (float.IsInfinity(num))
133 {
135 }
136 return new SqlSingle(num);
137 }
138
140 {
141 if (x.IsNull || y.IsNull)
142 {
143 return Null;
144 }
145 if (y._value == 0f)
146 {
148 }
149 float num = x._value / y._value;
150 if (float.IsInfinity(num))
151 {
153 }
154 return new SqlSingle(num);
155 }
156
157 public static explicit operator SqlSingle(SqlBoolean x)
158 {
159 if (!x.IsNull)
160 {
161 return new SqlSingle((int)x.ByteValue);
162 }
163 return Null;
164 }
165
166 public static implicit operator SqlSingle(SqlByte x)
167 {
168 if (!x.IsNull)
169 {
170 return new SqlSingle((int)x.Value);
171 }
172 return Null;
173 }
174
175 public static implicit operator SqlSingle(SqlInt16 x)
176 {
177 if (!x.IsNull)
178 {
179 return new SqlSingle(x.Value);
180 }
181 return Null;
182 }
183
184 public static implicit operator SqlSingle(SqlInt32 x)
185 {
186 if (!x.IsNull)
187 {
188 return new SqlSingle(x.Value);
189 }
190 return Null;
191 }
192
193 public static implicit operator SqlSingle(SqlInt64 x)
194 {
195 if (!x.IsNull)
196 {
197 return new SqlSingle(x.Value);
198 }
199 return Null;
200 }
201
202 public static implicit operator SqlSingle(SqlMoney x)
203 {
204 if (!x.IsNull)
205 {
206 return new SqlSingle(x.ToDouble());
207 }
208 return Null;
209 }
210
211 public static implicit operator SqlSingle(SqlDecimal x)
212 {
213 if (!x.IsNull)
214 {
215 return new SqlSingle(x.ToDouble());
216 }
217 return Null;
218 }
219
220 public static explicit operator SqlSingle(SqlDouble x)
221 {
222 if (!x.IsNull)
223 {
224 return new SqlSingle(x.Value);
225 }
226 return Null;
227 }
228
229 public static explicit operator SqlSingle(SqlString x)
230 {
231 if (x.IsNull)
232 {
233 return Null;
234 }
235 return Parse(x.Value);
236 }
237
239 {
240 if (!x.IsNull && !y.IsNull)
241 {
242 return new SqlBoolean(x._value == y._value);
243 }
244 return SqlBoolean.Null;
245 }
246
248 {
249 return !(x == y);
250 }
251
253 {
254 if (!x.IsNull && !y.IsNull)
255 {
256 return new SqlBoolean(x._value < y._value);
257 }
258 return SqlBoolean.Null;
259 }
260
262 {
263 if (!x.IsNull && !y.IsNull)
264 {
265 return new SqlBoolean(x._value > y._value);
266 }
267 return SqlBoolean.Null;
268 }
269
271 {
272 if (!x.IsNull && !y.IsNull)
273 {
274 return new SqlBoolean(x._value <= y._value);
275 }
276 return SqlBoolean.Null;
277 }
278
280 {
281 if (!x.IsNull && !y.IsNull)
282 {
283 return new SqlBoolean(x._value >= y._value);
284 }
285 return SqlBoolean.Null;
286 }
287
288 public static SqlSingle Add(SqlSingle x, SqlSingle y)
289 {
290 return x + y;
291 }
292
294 {
295 return x - y;
296 }
297
299 {
300 return x * y;
301 }
302
304 {
305 return x / y;
306 }
307
309 {
310 return x == y;
311 }
312
314 {
315 return x != y;
316 }
317
319 {
320 return x < y;
321 }
322
324 {
325 return x > y;
326 }
327
329 {
330 return x <= y;
331 }
332
334 {
335 return x >= y;
336 }
337
339 {
340 return (SqlBoolean)this;
341 }
342
344 {
345 return (SqlByte)this;
346 }
347
349 {
350 return this;
351 }
352
354 {
355 return (SqlInt16)this;
356 }
357
359 {
360 return (SqlInt32)this;
361 }
362
364 {
365 return (SqlInt64)this;
366 }
367
369 {
370 return (SqlMoney)this;
371 }
372
374 {
375 return (SqlDecimal)this;
376 }
377
379 {
380 return (SqlString)this;
381 }
382
383 public int CompareTo(object? value)
384 {
386 {
387 return CompareTo(value2);
388 }
389 throw ADP.WrongType(value.GetType(), typeof(SqlSingle));
390 }
391
393 {
394 if (IsNull)
395 {
396 if (!value.IsNull)
397 {
398 return -1;
399 }
400 return 0;
401 }
402 if (value.IsNull)
403 {
404 return 1;
405 }
406 if (this < value)
407 {
408 return -1;
409 }
410 if (this > value)
411 {
412 return 1;
413 }
414 return 0;
415 }
416
417 public override bool Equals([NotNullWhen(true)] object? value)
418 {
420 {
421 return false;
422 }
423 if (sqlSingle.IsNull || IsNull)
424 {
425 if (sqlSingle.IsNull)
426 {
427 return IsNull;
428 }
429 return false;
430 }
431 return (this == sqlSingle).Value;
432 }
433
434 public override int GetHashCode()
435 {
436 if (!IsNull)
437 {
438 return Value.GetHashCode();
439 }
440 return 0;
441 }
442
444 {
445 return null;
446 }
447
449 {
450 string attribute = reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
451 if (attribute != null && XmlConvert.ToBoolean(attribute))
452 {
453 reader.ReadElementString();
454 _fNotNull = false;
455 }
456 else
457 {
459 _fNotNull = true;
460 }
461 }
462
464 {
465 if (IsNull)
466 {
467 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
468 }
469 else
470 {
471 writer.WriteString(XmlConvert.ToString(_value));
472 }
473 }
474
476 {
477 return new XmlQualifiedName("float", "http://www.w3.org/2001/XMLSchema");
478 }
479}
static Exception WrongType(Type got, Type expected)
Definition ADP.cs:174
static CultureInfo InvariantCulture
static bool ToBoolean(string s)
static string ToString(bool value)
static float ToSingle(string s)
string? GetAttribute(string name)
virtual string ReadElementString()
Definition XmlReader.cs:667
static readonly SqlBoolean Null
Definition SqlBoolean.cs:21
static SqlBoolean NotEquals(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:313
int CompareTo(object? value)
Definition SqlSingle.cs:383
static readonly SqlSingle Null
Definition SqlSingle.cs:17
static SqlBoolean GreaterThan(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:323
static SqlSingle Subtract(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:293
static SqlSingle Divide(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:303
static SqlSingle operator-(SqlSingle x)
Definition SqlSingle.cs:88
static readonly SqlSingle MinValue
Definition SqlSingle.cs:21
static SqlSingle operator*(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:125
static SqlBoolean operator!=(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:247
static SqlBoolean Equals(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:308
static SqlBoolean operator>=(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:279
override bool Equals([NotNullWhen(true)] object? value)
Definition SqlSingle.cs:417
static SqlBoolean operator<=(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:270
static readonly SqlSingle Zero
Definition SqlSingle.cs:19
static SqlBoolean operator<(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:252
static SqlSingle operator/(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:139
static SqlBoolean GreaterThanOrEqual(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:333
static SqlBoolean LessThan(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:318
static SqlBoolean operator==(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:238
int CompareTo(SqlSingle value)
Definition SqlSingle.cs:392
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
Definition SqlSingle.cs:475
static SqlBoolean LessThanOrEqual(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:328
static SqlSingle Multiply(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:298
static SqlBoolean operator>(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:261
static readonly SqlSingle MaxValue
Definition SqlSingle.cs:23
override string ToString()
Definition SqlSingle.cs:70
static SqlSingle Add(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:288
static SqlSingle Parse(string s)
Definition SqlSingle.cs:79
static SqlSingle operator+(SqlSingle x, SqlSingle y)
Definition SqlSingle.cs:97