1 //------------------------------------------------------------------------------
2 // <copyright file="XmlILStorageConverter.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System.Collections.Generic;
11 using System.Xml.XPath;
12 using System.Xml.Schema;
14 using System.ComponentModel;
16 namespace System.Xml.Xsl.Runtime {
19 /// This is a simple convenience wrapper internal class that contains static helper methods that get a value
20 /// converter from XmlQueryRuntime and use it convert among several physical Clr representations for
21 /// the same logical Xml type. For example, an external function might have an argument typed as
22 /// xs:integer, with Clr type Decimal. Since ILGen stores xs:integer as Clr type Int64 instead of
23 /// Decimal, a conversion to the desired storage type must take place.
25 [EditorBrowsable(EditorBrowsableState.Never)]
26 public static class XmlILStorageConverter {
28 //-----------------------------------------------
30 //-----------------------------------------------
32 public static XmlAtomicValue StringToAtomicValue(string value, int index, XmlQueryRuntime runtime) {
33 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
36 public static XmlAtomicValue DecimalToAtomicValue(decimal value, int index, XmlQueryRuntime runtime) {
37 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
40 public static XmlAtomicValue Int64ToAtomicValue(long value, int index, XmlQueryRuntime runtime) {
41 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
44 public static XmlAtomicValue Int32ToAtomicValue(int value, int index, XmlQueryRuntime runtime) {
45 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
48 public static XmlAtomicValue BooleanToAtomicValue(bool value, int index, XmlQueryRuntime runtime) {
49 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
52 public static XmlAtomicValue DoubleToAtomicValue(double value, int index, XmlQueryRuntime runtime) {
53 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
56 public static XmlAtomicValue SingleToAtomicValue(float value, int index, XmlQueryRuntime runtime) {
57 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
60 public static XmlAtomicValue DateTimeToAtomicValue(DateTime value, int index, XmlQueryRuntime runtime) {
61 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
64 public static XmlAtomicValue XmlQualifiedNameToAtomicValue(XmlQualifiedName value, int index, XmlQueryRuntime runtime) {
65 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
68 public static XmlAtomicValue TimeSpanToAtomicValue(TimeSpan value, int index, XmlQueryRuntime runtime) {
69 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
72 public static XmlAtomicValue BytesToAtomicValue(byte[] value, int index, XmlQueryRuntime runtime) {
73 return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
76 public static IList<XPathItem> NavigatorsToItems(IList<XPathNavigator> listNavigators) {
77 // Check to see if the navigator cache implements IList<XPathItem>
78 IList<XPathItem> listItems = listNavigators as IList<XPathItem>;
79 if (listItems != null)
82 // Create XmlQueryNodeSequence, which does implement IList<XPathItem>
83 return new XmlQueryNodeSequence(listNavigators);
86 public static IList<XPathNavigator> ItemsToNavigators(IList<XPathItem> listItems) {
87 // Check to see if the navigator cache implements IList<XPathNavigator>
88 IList<XPathNavigator> listNavs = listItems as IList<XPathNavigator>;
92 // Create XmlQueryNodeSequence, which does implement IList<XPathNavigator>
93 XmlQueryNodeSequence seq = new XmlQueryNodeSequence(listItems.Count);
94 for (int i = 0; i < listItems.Count; i++)
95 seq.Add((XPathNavigator) listItems[i]);