The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.Runtime \ XmlILStorageConverter

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlILStorageConverter.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Collections.Generic;
  17. using System.IO;
  18. using System.Xml;
  19. using System.Xml.XPath;
  20. using System.Xml.Schema;
  21. using System.Xml.Xsl;
  22. using System.ComponentModel;
  23. namespace System.Xml.Xsl.Runtime
  24. {
  25.    
  26.     /// <summary>
  27.     /// This is a simple convenience wrapper internal class that contains static helper methods that get a value
  28.     /// converter from XmlQueryRuntime and use it convert among several physical Clr representations for
  29.     /// the same logical Xml type. For example, an external function might have an argument typed as
  30.     /// xs:integer, with Clr type Decimal. Since ILGen stores xs:integer as Clr type Int64 instead of
  31.     /// Decimal, a conversion to the desired storage type must take place.
  32.     /// </summary>
  33.     [EditorBrowsable(EditorBrowsableState.Never)]
  34.     public static class XmlILStorageConverter
  35.     {
  36.        
  37.         //-----------------------------------------------
  38.         // ToAtomicValue
  39.         //-----------------------------------------------
  40.        
  41.         public static XmlAtomicValue StringToAtomicValue(string value, int index, XmlQueryRuntime runtime)
  42.         {
  43.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  44.         }
  45.        
  46.         public static XmlAtomicValue DecimalToAtomicValue(decimal value, int index, XmlQueryRuntime runtime)
  47.         {
  48.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  49.         }
  50.        
  51.         public static XmlAtomicValue Int64ToAtomicValue(long value, int index, XmlQueryRuntime runtime)
  52.         {
  53.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  54.         }
  55.        
  56.         public static XmlAtomicValue Int32ToAtomicValue(int value, int index, XmlQueryRuntime runtime)
  57.         {
  58.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  59.         }
  60.        
  61.         public static XmlAtomicValue BooleanToAtomicValue(bool value, int index, XmlQueryRuntime runtime)
  62.         {
  63.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  64.         }
  65.        
  66.         public static XmlAtomicValue DoubleToAtomicValue(double value, int index, XmlQueryRuntime runtime)
  67.         {
  68.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  69.         }
  70.        
  71.         public static XmlAtomicValue SingleToAtomicValue(float value, int index, XmlQueryRuntime runtime)
  72.         {
  73.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  74.         }
  75.        
  76.         public static XmlAtomicValue DateTimeToAtomicValue(DateTime value, int index, XmlQueryRuntime runtime)
  77.         {
  78.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  79.         }
  80.        
  81.         public static XmlAtomicValue XmlQualifiedNameToAtomicValue(XmlQualifiedName value, int index, XmlQueryRuntime runtime)
  82.         {
  83.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  84.         }
  85.        
  86.         public static XmlAtomicValue TimeSpanToAtomicValue(TimeSpan value, int index, XmlQueryRuntime runtime)
  87.         {
  88.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  89.         }
  90.        
  91.         public static XmlAtomicValue BytesToAtomicValue(byte[] value, int index, XmlQueryRuntime runtime)
  92.         {
  93.             return new XmlAtomicValue(runtime.GetXmlType(index).SchemaType, value);
  94.         }
  95.        
  96.         public static IList<XPathItem> NavigatorsToItems(IList<XPathNavigator> listNavigators)
  97.         {
  98.             // Check to see if the navigator cache implements IList<XPathItem>
  99.             IList<XPathItem> listItems = listNavigators as IList<XPathItem>;
  100.             if (listItems != null)
  101.                 return listItems;
  102.            
  103.             // Create XmlQueryNodeSequence, which does implement IList<XPathItem>
  104.             return new XmlQueryNodeSequence(listNavigators);
  105.         }
  106.        
  107.         public static IList<XPathNavigator> ItemsToNavigators(IList<XPathItem> listItems)
  108.         {
  109.             // Check to see if the navigator cache implements IList<XPathNavigator>
  110.             IList<XPathNavigator> listNavs = listItems as IList<XPathNavigator>;
  111.             if (listNavs != null)
  112.                 return listNavs;
  113.            
  114.             // Create XmlQueryNodeSequence, which does implement IList<XPathNavigator>
  115.             XmlQueryNodeSequence seq = new XmlQueryNodeSequence(listItems.Count);
  116.             for (int i = 0; i < listItems.Count; i++)
  117.                 seq.Add((XPathNavigator)listItems[i]);
  118.            
  119.             return seq;
  120.         }
  121.     }
  122. }

Developer Fusion