Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XsltConvert.cs
Go to the documentation of this file.
6
8
10public static class XsltConvert
11{
12 internal static readonly Type BooleanType = typeof(bool);
13
14 internal static readonly Type ByteArrayType = typeof(byte[]);
15
16 internal static readonly Type ByteType = typeof(byte);
17
18 internal static readonly Type DateTimeType = typeof(DateTime);
19
20 internal static readonly Type DecimalType = typeof(decimal);
21
22 internal static readonly Type DoubleType = typeof(double);
23
24 internal static readonly Type ICollectionType = typeof(ICollection);
25
26 internal static readonly Type IEnumerableType = typeof(IEnumerable);
27
28 internal static readonly Type IListType = typeof(IList);
29
30 internal static readonly Type Int16Type = typeof(short);
31
32 internal static readonly Type Int32Type = typeof(int);
33
34 internal static readonly Type Int64Type = typeof(long);
35
36 internal static readonly Type IXPathNavigableType = typeof(IXPathNavigable);
37
38 internal static readonly Type ObjectType = typeof(object);
39
40 internal static readonly Type SByteType = typeof(sbyte);
41
42 internal static readonly Type SingleType = typeof(float);
43
44 internal static readonly Type StringType = typeof(string);
45
46 internal static readonly Type TimeSpanType = typeof(TimeSpan);
47
48 internal static readonly Type UInt16Type = typeof(ushort);
49
50 internal static readonly Type UInt32Type = typeof(uint);
51
52 internal static readonly Type UInt64Type = typeof(ulong);
53
54 internal static readonly Type UriType = typeof(Uri);
55
56 internal static readonly Type VoidType = typeof(void);
57
58 internal static readonly Type XmlAtomicValueType = typeof(XmlAtomicValue);
59
60 internal static readonly Type XmlQualifiedNameType = typeof(XmlQualifiedName);
61
62 internal static readonly Type XPathItemType = typeof(XPathItem);
63
64 internal static readonly Type XPathNavigatorArrayType = typeof(XPathNavigator[]);
65
66 internal static readonly Type XPathNavigatorType = typeof(XPathNavigator);
67
69
70 public static bool ToBoolean(XPathItem item)
71 {
72 if (item.IsNode)
73 {
74 return true;
75 }
76 Type valueType = item.ValueType;
77 if (valueType == StringType)
78 {
79 return item.Value.Length != 0;
80 }
81 if (valueType == DoubleType)
82 {
83 double valueAsDouble = item.ValueAsDouble;
84 if (!(valueAsDouble < 0.0))
85 {
86 return 0.0 < valueAsDouble;
87 }
88 return true;
89 }
90 return item.ValueAsBoolean;
91 }
92
94 {
95 if (listItems.Count == 0)
96 {
97 return false;
98 }
99 return ToBoolean(listItems[0]);
100 }
101
102 public static double ToDouble(string value)
103 {
105 }
106
107 public static double ToDouble(XPathItem item)
108 {
109 if (item.IsNode)
110 {
111 return XPathConvert.StringToDouble(item.Value);
112 }
113 Type valueType = item.ValueType;
114 if (valueType == StringType)
115 {
116 return XPathConvert.StringToDouble(item.Value);
117 }
118 if (valueType == DoubleType)
119 {
120 return item.ValueAsDouble;
121 }
122 if (!item.ValueAsBoolean)
123 {
124 return 0.0;
125 }
126 return 1.0;
127 }
128
129 public static double ToDouble(IList<XPathItem> listItems)
130 {
131 if (listItems.Count == 0)
132 {
133 return double.NaN;
134 }
135 return ToDouble(listItems[0]);
136 }
137
139 {
140 if (!item.IsNode)
141 {
143 XmlRawWriter xmlRawWriter = xPathDocument.LoadFromWriter(XPathDocument.LoadFlags.AtomizeNames, string.Empty);
144 xmlRawWriter.WriteString(ToString(item));
145 xmlRawWriter.Close();
146 return xPathDocument.CreateNavigator();
147 }
149 {
150 return rtfNavigator.ToNavigator();
151 }
152 return (XPathNavigator)item;
153 }
154
156 {
157 if (listItems.Count == 1)
158 {
159 return ToNode(listItems[0]);
160 }
161 throw new XslTransformException(System.SR.Xslt_NodeSetNotNode, string.Empty);
162 }
163
165 {
166 return new XmlQueryNodeSequence(ToNode(item));
167 }
168
177
178 public static string ToString(double value)
179 {
181 }
182
183 public static string ToString(XPathItem item)
184 {
185 if (!item.IsNode && item.ValueType == DoubleType)
186 {
187 return XPathConvert.DoubleToString(item.ValueAsDouble);
188 }
189 return item.Value;
190 }
191
192 public static string ToString(IList<XPathItem> listItems)
193 {
194 if (listItems.Count == 0)
195 {
196 return string.Empty;
197 }
198 return ToString(listItems[0]);
199 }
200
201 public static string ToString(DateTime value)
202 {
203 return new XsdDateTime(value, XsdDateTimeFlags.DateTime).ToString();
204 }
205
206 public static double ToDouble(decimal value)
207 {
208 return (double)value;
209 }
210
211 public static double ToDouble(int value)
212 {
213 return value;
214 }
215
216 public static double ToDouble(long value)
217 {
218 return value;
219 }
220
221 public static decimal ToDecimal(double value)
222 {
223 return (decimal)value;
224 }
225
226 public static int ToInt(double value)
227 {
228 return checked((int)value);
229 }
230
231 public static long ToLong(double value)
232 {
233 return checked((long)value);
234 }
235
236 public static DateTime ToDateTime(string value)
237 {
238 return new XsdDateTime(value, XsdDateTimeFlags.AllXsd);
239 }
240
242 {
243 switch (destinationType.TypeCode)
244 {
245 case XmlTypeCode.Boolean:
246 {
247 XmlTypeCode typeCode = value.XmlType.TypeCode;
248 if ((uint)(typeCode - 12) <= 1u || typeCode == XmlTypeCode.Double)
249 {
250 return new XmlAtomicValue(destinationType.SchemaType, ToBoolean(value));
251 }
252 break;
253 }
254 case XmlTypeCode.DateTime:
255 if (value.XmlType.TypeCode == XmlTypeCode.String)
256 {
257 return new XmlAtomicValue(destinationType.SchemaType, ToDateTime(value.Value));
258 }
259 break;
260 case XmlTypeCode.Decimal:
261 if (value.XmlType.TypeCode == XmlTypeCode.Double)
262 {
263 return new XmlAtomicValue(destinationType.SchemaType, ToDecimal(value.ValueAsDouble));
264 }
265 break;
266 case XmlTypeCode.Double:
267 switch (value.XmlType.TypeCode)
268 {
269 case XmlTypeCode.String:
270 case XmlTypeCode.Boolean:
271 case XmlTypeCode.Double:
272 return new XmlAtomicValue(destinationType.SchemaType, ToDouble(value));
273 case XmlTypeCode.Decimal:
274 return new XmlAtomicValue(destinationType.SchemaType, ToDouble((decimal)value.ValueAs(DecimalType, null)));
275 case XmlTypeCode.Long:
276 case XmlTypeCode.Int:
277 return new XmlAtomicValue(destinationType.SchemaType, ToDouble(value.ValueAsLong));
278 }
279 break;
280 case XmlTypeCode.Long:
281 case XmlTypeCode.Int:
282 if (value.XmlType.TypeCode == XmlTypeCode.Double)
283 {
284 return new XmlAtomicValue(destinationType.SchemaType, ToLong(value.ValueAsDouble));
285 }
286 break;
287 case XmlTypeCode.String:
288 switch (value.XmlType.TypeCode)
289 {
290 case XmlTypeCode.String:
291 case XmlTypeCode.Boolean:
292 case XmlTypeCode.Double:
293 return new XmlAtomicValue(destinationType.SchemaType, ToString(value));
294 case XmlTypeCode.DateTime:
295 return new XmlAtomicValue(destinationType.SchemaType, ToString(value.ValueAsDateTime));
296 }
297 break;
298 }
299 return value;
300 }
301
303 {
304 if (listItems.Count == 1)
305 {
307 if (!xPathItem.IsNode)
308 {
309 throw new XslTransformException(System.SR.XPath_NodeSetExpected, string.Empty);
310 }
312 {
313 throw new XslTransformException(System.SR.XPath_RtfInPathExpr, string.Empty);
314 }
315 }
317 }
318
320 {
321 if (clrType == BooleanType)
322 {
324 }
325 if (clrType == ByteType)
326 {
328 }
329 if (clrType == DecimalType)
330 {
332 }
333 if (clrType == DateTimeType)
334 {
336 }
337 if (clrType == DoubleType)
338 {
340 }
341 if (clrType == Int16Type)
342 {
344 }
345 if (clrType == Int32Type)
346 {
348 }
349 if (clrType == Int64Type)
350 {
352 }
354 {
356 }
357 if (clrType == SByteType)
358 {
360 }
361 if (clrType == SingleType)
362 {
364 }
365 if (clrType == StringType)
366 {
368 }
369 if (clrType == UInt16Type)
370 {
372 }
373 if (clrType == UInt32Type)
374 {
376 }
377 if (clrType == UInt64Type)
378 {
380 }
382 {
384 }
386 {
388 }
390 {
392 }
393 if (clrType.IsEnum)
394 {
396 }
397 if (clrType == VoidType)
398 {
400 }
402 }
403}
static string XPath_NodeSetExpected
Definition SR.cs:1856
static string Xslt_NodeSetNotNode
Definition SR.cs:1990
static string XPath_RtfInPathExpr
Definition SR.cs:1858
Definition SR.cs:7
static IList< XPathNavigator > ItemsToNavigators(IList< XPathItem > listItems)
static double ToDouble(int value)
static readonly Type IEnumerableType
static XPathNavigator ToNode(IList< XPathItem > listItems)
static readonly Type XPathNavigatorArrayType
static readonly Type ObjectType
static readonly Type IXPathNavigableType
static double ToDouble(IList< XPathItem > listItems)
static readonly Type ICollectionType
static readonly Type BooleanType
static XmlQueryType InferXsltType(Type clrType)
static readonly Type XmlAtomicValueType
static readonly Type StringType
static IList< XPathNavigator > ToNodeSet(XPathItem item)
static readonly Type SByteType
static readonly Type ByteType
static IList< XPathNavigator > ToNodeSet(IList< XPathItem > listItems)
static double ToDouble(long value)
static bool ToBoolean(XPathItem item)
static XPathNavigator ToNode(XPathItem item)
static readonly Type VoidType
static decimal ToDecimal(double value)
static readonly Type ByteArrayType
static readonly Type DoubleType
static double ToDouble(XPathItem item)
static XmlAtomicValue ConvertToType(XmlAtomicValue value, XmlQueryType destinationType)
static readonly Type SingleType
static int ToInt(double value)
static bool ToBoolean(IList< XPathItem > listItems)
static readonly Type DecimalType
static double ToDouble(string value)
static double ToDouble(decimal value)
static string ToString(XPathItem item)
static DateTime ToDateTime(string value)
static readonly Type UInt16Type
static readonly Type Int16Type
static readonly Type DateTimeType
static string ToString(double value)
static IList< XPathNavigator > EnsureNodeSet(IList< XPathItem > listItems)
static string ToString(DateTime value)
static readonly Type XPathItemType
static readonly Type Int32Type
static long ToLong(double value)
static readonly Type TimeSpanType
static readonly Type Int64Type
static readonly Type XPathNodeIteratorType
static readonly Type UInt64Type
static readonly Type XmlQualifiedNameType
static readonly Type UInt32Type
static string ToString(IList< XPathItem > listItems)
static readonly Type XPathNavigatorType
static readonly Type IListType
static unsafe double StringToDouble(string s)
static unsafe string DoubleToString(double dbl)
static readonly XmlQueryType NodeSDod
static readonly XmlQueryType DoubleX
static readonly XmlQueryType StringX
static readonly XmlQueryType ItemS
static readonly XmlQueryType BooleanX
static readonly XmlQueryType NodeNotRtf
static readonly XmlQueryType Empty