Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlAtomicValue.cs
Go to the documentation of this file.
4
5namespace System.Xml.Schema;
6
7public sealed class XmlAtomicValue : XPathItem, ICloneable
8{
9 [StructLayout(LayoutKind.Explicit, Size = 8)]
10 private struct Union
11 {
12 [FieldOffset(0)]
13 public bool boolVal;
14
15 [FieldOffset(0)]
16 public double dblVal;
17
18 [FieldOffset(0)]
19 public long i64Val;
20
21 [FieldOffset(0)]
22 public int i32Val;
23
24 [FieldOffset(0)]
26 }
27
29 {
30 public string prefix;
31
32 public string ns;
33
34 public NamespacePrefixForQName(string prefix, string ns)
35 {
36 this.ns = ns;
38 }
39
40 public string LookupNamespace(string prefix)
41 {
42 if (prefix == this.prefix)
43 {
44 return ns;
45 }
46 return null;
47 }
48
49 public string LookupPrefix(string namespaceName)
50 {
51 if (ns == namespaceName)
52 {
53 return prefix;
54 }
55 return null;
56 }
57
64 }
65
66 private readonly XmlSchemaType _xmlType;
67
68 private readonly object _objVal;
69
70 private readonly TypeCode _clrType;
71
73
75
76 public override bool IsNode => false;
77
78 public override XmlSchemaType XmlType => _xmlType;
79
81
82 public override object TypedValue
83 {
84 get
85 {
87 if (_objVal == null)
88 {
89 switch (_clrType)
90 {
91 case TypeCode.Boolean:
92 return valueConverter.ChangeType(_unionVal.boolVal, ValueType);
93 case TypeCode.Int32:
94 return valueConverter.ChangeType(_unionVal.i32Val, ValueType);
95 case TypeCode.Int64:
96 return valueConverter.ChangeType(_unionVal.i64Val, ValueType);
97 case TypeCode.Double:
98 return valueConverter.ChangeType(_unionVal.dblVal, ValueType);
99 case TypeCode.DateTime:
100 return valueConverter.ChangeType(_unionVal.dtVal, ValueType);
101 }
102 }
103 return valueConverter.ChangeType(_objVal, ValueType, _nsPrefix);
104 }
105 }
106
107 public override bool ValueAsBoolean
108 {
109 get
110 {
112 if (_objVal == null)
113 {
114 switch (_clrType)
115 {
116 case TypeCode.Boolean:
117 return _unionVal.boolVal;
118 case TypeCode.Int32:
119 return valueConverter.ToBoolean(_unionVal.i32Val);
120 case TypeCode.Int64:
121 return valueConverter.ToBoolean(_unionVal.i64Val);
122 case TypeCode.Double:
123 return valueConverter.ToBoolean(_unionVal.dblVal);
124 case TypeCode.DateTime:
125 return valueConverter.ToBoolean(_unionVal.dtVal);
126 }
127 }
128 return valueConverter.ToBoolean(_objVal);
129 }
130 }
131
132 public override DateTime ValueAsDateTime
133 {
134 get
135 {
137 if (_objVal == null)
138 {
139 switch (_clrType)
140 {
141 case TypeCode.Boolean:
142 return valueConverter.ToDateTime(_unionVal.boolVal);
143 case TypeCode.Int32:
144 return valueConverter.ToDateTime(_unionVal.i32Val);
145 case TypeCode.Int64:
146 return valueConverter.ToDateTime(_unionVal.i64Val);
147 case TypeCode.Double:
148 return valueConverter.ToDateTime(_unionVal.dblVal);
149 case TypeCode.DateTime:
150 return _unionVal.dtVal;
151 }
152 }
153 return valueConverter.ToDateTime(_objVal);
154 }
155 }
156
157 public override double ValueAsDouble
158 {
159 get
160 {
162 if (_objVal == null)
163 {
164 switch (_clrType)
165 {
166 case TypeCode.Boolean:
167 return valueConverter.ToDouble(_unionVal.boolVal);
168 case TypeCode.Int32:
169 return valueConverter.ToDouble(_unionVal.i32Val);
170 case TypeCode.Int64:
171 return valueConverter.ToDouble(_unionVal.i64Val);
172 case TypeCode.Double:
173 return _unionVal.dblVal;
174 case TypeCode.DateTime:
175 return valueConverter.ToDouble(_unionVal.dtVal);
176 }
177 }
178 return valueConverter.ToDouble(_objVal);
179 }
180 }
181
182 public override int ValueAsInt
183 {
184 get
185 {
187 if (_objVal == null)
188 {
189 switch (_clrType)
190 {
191 case TypeCode.Boolean:
192 return valueConverter.ToInt32(_unionVal.boolVal);
193 case TypeCode.Int32:
194 return _unionVal.i32Val;
195 case TypeCode.Int64:
196 return valueConverter.ToInt32(_unionVal.i64Val);
197 case TypeCode.Double:
198 return valueConverter.ToInt32(_unionVal.dblVal);
199 case TypeCode.DateTime:
200 return valueConverter.ToInt32(_unionVal.dtVal);
201 }
202 }
203 return valueConverter.ToInt32(_objVal);
204 }
205 }
206
207 public override long ValueAsLong
208 {
209 get
210 {
212 if (_objVal == null)
213 {
214 switch (_clrType)
215 {
216 case TypeCode.Boolean:
217 return valueConverter.ToInt64(_unionVal.boolVal);
218 case TypeCode.Int32:
219 return valueConverter.ToInt64(_unionVal.i32Val);
220 case TypeCode.Int64:
221 return _unionVal.i64Val;
222 case TypeCode.Double:
223 return valueConverter.ToInt64(_unionVal.dblVal);
224 case TypeCode.DateTime:
225 return valueConverter.ToInt64(_unionVal.dtVal);
226 }
227 }
228 return valueConverter.ToInt64(_objVal);
229 }
230 }
231
232 public override string Value
233 {
234 get
235 {
237 if (_objVal == null)
238 {
239 switch (_clrType)
240 {
241 case TypeCode.Boolean:
242 return valueConverter.ToString(_unionVal.boolVal);
243 case TypeCode.Int32:
244 return valueConverter.ToString(_unionVal.i32Val);
245 case TypeCode.Int64:
246 return valueConverter.ToString(_unionVal.i64Val);
247 case TypeCode.Double:
248 return valueConverter.ToString(_unionVal.dblVal);
249 case TypeCode.DateTime:
250 return valueConverter.ToString(_unionVal.dtVal);
251 }
252 }
253 return valueConverter.ToString(_objVal, _nsPrefix);
254 }
255 }
256
257 internal XmlAtomicValue(XmlSchemaType xmlType, bool value)
258 {
259 if (xmlType == null)
260 {
261 throw new ArgumentNullException("xmlType");
262 }
263 _xmlType = xmlType;
264 _clrType = TypeCode.Boolean;
266 }
267
269 {
270 if (xmlType == null)
271 {
272 throw new ArgumentNullException("xmlType");
273 }
274 _xmlType = xmlType;
275 _clrType = TypeCode.DateTime;
277 }
278
279 internal XmlAtomicValue(XmlSchemaType xmlType, double value)
280 {
281 if (xmlType == null)
282 {
283 throw new ArgumentNullException("xmlType");
284 }
285 _xmlType = xmlType;
286 _clrType = TypeCode.Double;
288 }
289
290 internal XmlAtomicValue(XmlSchemaType xmlType, int value)
291 {
292 if (xmlType == null)
293 {
294 throw new ArgumentNullException("xmlType");
295 }
296 _xmlType = xmlType;
297 _clrType = TypeCode.Int32;
299 }
300
301 internal XmlAtomicValue(XmlSchemaType xmlType, long value)
302 {
303 if (xmlType == null)
304 {
305 throw new ArgumentNullException("xmlType");
306 }
307 _xmlType = xmlType;
308 _clrType = TypeCode.Int64;
310 }
311
312 internal XmlAtomicValue(XmlSchemaType xmlType, string value)
313 {
314 if (value == null)
315 {
316 throw new ArgumentNullException("value");
317 }
318 if (xmlType == null)
319 {
320 throw new ArgumentNullException("xmlType");
321 }
322 _xmlType = xmlType;
323 _objVal = value;
324 }
325
327 {
328 if (value == null)
329 {
330 throw new ArgumentNullException("value");
331 }
332 if (xmlType == null)
333 {
334 throw new ArgumentNullException("xmlType");
335 }
336 _xmlType = xmlType;
337 _objVal = value;
338 if (nsResolver != null && (_xmlType.TypeCode == XmlTypeCode.QName || _xmlType.TypeCode == XmlTypeCode.Notation))
339 {
342 }
343 }
344
345 internal XmlAtomicValue(XmlSchemaType xmlType, object value)
346 {
347 if (value == null)
348 {
349 throw new ArgumentNullException("value");
350 }
351 if (xmlType == null)
352 {
353 throw new ArgumentNullException("xmlType");
354 }
355 _xmlType = xmlType;
356 _objVal = value;
357 }
358
360 {
361 if (value == null)
362 {
363 throw new ArgumentNullException("value");
364 }
365 if (xmlType == null)
366 {
367 throw new ArgumentNullException("xmlType");
368 }
369 _xmlType = xmlType;
370 _objVal = value;
371 if (nsResolver != null && (_xmlType.TypeCode == XmlTypeCode.QName || _xmlType.TypeCode == XmlTypeCode.Notation))
372 {
374 string @namespace = xmlQualifiedName.Namespace;
375 _nsPrefix = new NamespacePrefixForQName(nsResolver.LookupPrefix(@namespace), @namespace);
376 }
377 }
378
380 {
381 return this;
382 }
383
385 {
386 return this;
387 }
388
390 {
393 {
394 return this;
395 }
396 if (_objVal == null)
397 {
398 switch (_clrType)
399 {
400 case TypeCode.Boolean:
401 return valueConverter.ChangeType(_unionVal.boolVal, type);
402 case TypeCode.Int32:
403 return valueConverter.ChangeType(_unionVal.i32Val, type);
404 case TypeCode.Int64:
405 return valueConverter.ChangeType(_unionVal.i64Val, type);
406 case TypeCode.Double:
407 return valueConverter.ChangeType(_unionVal.dblVal, type);
408 case TypeCode.DateTime:
409 return valueConverter.ChangeType(_unionVal.dtVal, type);
410 }
411 }
412 return valueConverter.ChangeType(_objVal, type, nsResolver);
413 }
414
415 public override string ToString()
416 {
417 return Value;
418 }
419
420 private string GetPrefixFromQName(string value)
421 {
422 int colonOffset;
424 if (num == 0 || num != value.Length)
425 {
426 return null;
427 }
428 if (colonOffset != 0)
429 {
430 return value.Substring(0, colonOffset);
431 }
432 return string.Empty;
433 }
434}
IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
XmlAtomicValue(XmlSchemaType xmlType, object value, IXmlNamespaceResolver nsResolver)
XmlAtomicValue(XmlSchemaType xmlType, string value)
XmlAtomicValue(XmlSchemaType xmlType, string value, IXmlNamespaceResolver nsResolver)
XmlAtomicValue(XmlSchemaType xmlType, DateTime value)
readonly NamespacePrefixForQName _nsPrefix
XmlAtomicValue(XmlSchemaType xmlType, object value)
string GetPrefixFromQName(string value)
XmlAtomicValue(XmlSchemaType xmlType, bool value)
XmlAtomicValue(XmlSchemaType xmlType, int value)
XmlAtomicValue(XmlSchemaType xmlType, double value)
readonly XmlSchemaType _xmlType
override object ValueAs(Type type, IXmlNamespaceResolver? nsResolver)
XmlAtomicValue(XmlSchemaType xmlType, long value)
override XmlSchemaType XmlType
static int ParseQName(string s, int offset, out int colonOffset)
TypeCode
Definition TypeCode.cs:4