Converter

  1. // ==++==
  2. // 
  3. //   
  4. //    Copyright (c) 2002 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. // 
  14. // ==--==
  15. //============================================================
  16. //
  17. // Class: Converter
  18. // Purpose: Hexify and bin.base64 conversions
  19. //
  20. // Date:  June 10, 1999
  21. //
  22. //============================================================
  23. namespace System.Runtime.Serialization.Formatters.Soap {
  24.     using System.Threading;
  25.     using System.Runtime.Remoting;
  26.     using System.Runtime.Remoting.Metadata; 
  27.     using System.Runtime.Remoting.Metadata.W3cXsd2001; 
  28.     using System.Runtime.Serialization;
  29.     using System;
  30.     using System.Reflection;
  31.     using System.Globalization;
  32.     using System.Text;
  33.     using System.Security.Permissions;
  34.     sealed internal class Converter
  35.     {
  36.         private Converter()
  37.         {
  38.         }
  39.         private static int primitiveTypeEnumLength = 46; //Number of PrimitiveTypeEnums
  40.         // The following section are utilities to read and write XML types
  41.         // Translates a runtime type into an enumeration code
  42.         internal static InternalPrimitiveTypeE SoapToCode(Type type)
  43.         {
  44.             return ToCode(type);
  45.         }
  46.         internal static InternalPrimitiveTypeE ToCode(Type type)
  47.         {
  48.             InternalST.Soap("Converter""ToCode Type Entry ",type," IsEnum "+type.IsEnum);         
  49.             InternalPrimitiveTypeE code = InternalPrimitiveTypeE.Invalid;
  50.             if (type.IsEnum)
  51.                 return code = InternalPrimitiveTypeE.Invalid;
  52.             TypeCode typeCode = Type.GetTypeCode(type);
  53.             if (typeCode == TypeCode.Object)
  54.             {
  55.                 if (typeofISoapXsd.IsAssignableFrom(type))
  56.                 {
  57.                     if (type == typeofSoapTime)
  58.                         code = InternalPrimitiveTypeE.Time;
  59.                     else if (type == typeofSoapDate)
  60.                         code = InternalPrimitiveTypeE.Date;
  61.                     else if (type == typeofSoapYearMonth)
  62.                         code = InternalPrimitiveTypeE.YearMonth;
  63.                     else if (type == typeofSoapYear)
  64.                         code = InternalPrimitiveTypeE.Year;
  65.                     else if (type == typeofSoapMonthDay)
  66.                         code = InternalPrimitiveTypeE.MonthDay;
  67.                     else if (type == typeofSoapDay)
  68.                         code = InternalPrimitiveTypeE.Day;
  69.                     else if (type == typeofSoapMonth)
  70.                         code = InternalPrimitiveTypeE.Month;
  71.                     else if (type == typeofSoapHexBinary)
  72.                         code = InternalPrimitiveTypeE.HexBinary;
  73.                     else if (type == typeofSoapBase64Binary)
  74.                         code = InternalPrimitiveTypeE.Base64Binary;
  75.                     else if (type == typeofSoapInteger)
  76.                         code = InternalPrimitiveTypeE.Integer;
  77.                     else if (type == typeofSoapPositiveInteger)
  78.                         code = InternalPrimitiveTypeE.PositiveInteger;
  79.                     else if (type == typeofSoapNonPositiveInteger)
  80.                         code = InternalPrimitiveTypeE.NonPositiveInteger;
  81.                     else if (type == typeofSoapNonNegativeInteger)
  82.                         code = InternalPrimitiveTypeE.NonNegativeInteger;
  83.                     else if (type == typeofSoapNegativeInteger)
  84.                         code = InternalPrimitiveTypeE.NegativeInteger;
  85.                     else if (type == typeofSoapAnyUri)
  86.                         code = InternalPrimitiveTypeE.AnyUri;
  87.                     else if (type == typeofSoapQName)
  88.                         code = InternalPrimitiveTypeE.QName;
  89.                     else if (type == typeofSoapNotation)
  90.                         code = InternalPrimitiveTypeE.Notation;
  91.                     else if (type == typeofSoapNormalizedString)
  92.                         code = InternalPrimitiveTypeE.NormalizedString;
  93.                     else if (type == typeofSoapToken)
  94.                         code = InternalPrimitiveTypeE.Token;
  95.                     else if (type == typeofSoapLanguage)
  96.                         code = InternalPrimitiveTypeE.Language;
  97.                     else if (type == typeofSoapName)
  98.                         code = InternalPrimitiveTypeE.Name;
  99.                     else if (type == typeofSoapIdrefs)
  100.                         code = InternalPrimitiveTypeE.Idrefs;
  101.                     else if (type == typeofSoapEntities)
  102.                         code = InternalPrimitiveTypeE.Entities;
  103.                     else if (type == typeofSoapNmtoken)
  104.                         code = InternalPrimitiveTypeE.Nmtoken;
  105.                     else if (type == typeofSoapNmtokens)
  106.                         code = InternalPrimitiveTypeE.Nmtokens;
  107.                     else if (type == typeofSoapNcName)
  108.                         code = InternalPrimitiveTypeE.NcName;
  109.                     else if (type == typeofSoapId)
  110.                         code = InternalPrimitiveTypeE.Id;
  111.                     else if (type == typeofSoapIdref)
  112.                         code = InternalPrimitiveTypeE.Idref;
  113.                     else if (type == typeofSoapEntity)
  114.                         code = InternalPrimitiveTypeE.Entity;
  115.                 }
  116.                 else
  117.                 {
  118.                     if (type ==  typeofTimeSpan)
  119.                         code = InternalPrimitiveTypeE.TimeSpan;
  120.                     else
  121.                         code = InternalPrimitiveTypeE.Invalid;
  122.                 }
  123.             }
  124.             else
  125.                 code = ToPrimitiveTypeEnum(typeCode);
  126.             InternalST.Soap("Converter""ToCode Exit " , ((Enum)code).ToString());
  127.             return code;
  128.         }
  129.         // Translates a String into a runtime type enumeration code.
  130.         // The types translated are COM+ runtime types and XML Data Types
  131.         internal static InternalPrimitiveTypeE SoapToCode(String value)
  132.         {
  133.             return ToCode(value);
  134.         }
  135.         internal static InternalPrimitiveTypeE ToCode(String value)
  136.         {
  137.             InternalST.Soap("Converter""ToCode String Entry ",value);
  138.             if (value == null)
  139.                 throw new ArgumentNullException("serParser", String.Format(SoapUtil.GetResourceString("ArgumentNull_WithParamName"), value));
  140.             String lxsdType = value.ToLower(CultureInfo.InvariantCulture);
  141.             Char firstChar = lxsdType[0];
  142.             InternalPrimitiveTypeE code = InternalPrimitiveTypeE.Invalid;           
  143.             switch (firstChar)
  144.             {   
  145.                 case 'a':
  146.                     if (lxsdType == "anyuri")
  147.                         code = InternalPrimitiveTypeE.AnyUri;
  148.                     break;
  149.                 case 'b':
  150.                     if (lxsdType == "boolean")
  151.                         code = InternalPrimitiveTypeE.Boolean;
  152.                     else if (lxsdType == "byte")
  153.                         code = InternalPrimitiveTypeE.SByte;
  154.                     else if (lxsdType == "base64binary")
  155.                         code = InternalPrimitiveTypeE.Base64Binary;
  156.                     else if (lxsdType == "base64")
  157.                         code = InternalPrimitiveTypeE.Base64Binary;
  158.                     break;
  159.                 case 'c':
  160.                     if ((lxsdType == "char") || (lxsdType == "character")) // Not xsd types
  161.                         code = InternalPrimitiveTypeE.Char;
  162.                     break;
  163.                 case 'd':
  164.                     if (lxsdType == "double")
  165.                         code = InternalPrimitiveTypeE.Double;
  166.                     if (lxsdType == "datetime")
  167.                         code = InternalPrimitiveTypeE.DateTime;
  168.                     else if (lxsdType == "duration")
  169.                         code = InternalPrimitiveTypeE.TimeSpan;
  170.                     else if (lxsdType == "date")
  171.                         code = InternalPrimitiveTypeE.Date;
  172.                     else if (lxsdType == "decimal")  
  173.                         code = InternalPrimitiveTypeE.Decimal; 
  174.                     break;
  175.                 case 'e':
  176.                     if (lxsdType == "entities")
  177.                         code = InternalPrimitiveTypeE.Entities;
  178.                     else if (lxsdType == "entity")
  179.                         code = InternalPrimitiveTypeE.Entity;
  180.                     break;
  181.                 case 'f':
  182.                     if (lxsdType == "float")
  183.                         code = InternalPrimitiveTypeE.Single;
  184.                     break;
  185.                 case 'g':
  186.                     if (lxsdType == "gyearmonth")
  187.                         code = InternalPrimitiveTypeE.YearMonth;
  188.                     else if (lxsdType == "gyear")
  189.                         code = InternalPrimitiveTypeE.Year;
  190.                     else if (lxsdType == "gmonthday")
  191.                         code = InternalPrimitiveTypeE.MonthDay;
  192.                     else if (lxsdType == "gday")
  193.                         code = InternalPrimitiveTypeE.Day;
  194.                     else if (lxsdType == "gmonth")
  195.                         code = InternalPrimitiveTypeE.Month;
  196.                     break;
  197.                 case 'h':
  198.                     if (lxsdType == "hexbinary")
  199.                         code = InternalPrimitiveTypeE.HexBinary;
  200.                     break;
  201.                 case 'i':
  202.                     if (lxsdType == "int")
  203.                         code = InternalPrimitiveTypeE.Int32;
  204.                     if (lxsdType == "integer")
  205.                         code = InternalPrimitiveTypeE.Integer;
  206.                     else if (lxsdType == "idrefs")
  207.                         code = InternalPrimitiveTypeE.Idrefs;
  208.                     else if (lxsdType == "id")
  209.                         code = InternalPrimitiveTypeE.Id;
  210.                     else if (lxsdType == "idref")
  211.                         code = InternalPrimitiveTypeE.Idref;
  212.                     break;
  213.                 case 'l':
  214.                     if (lxsdType == "long")
  215.                         code = InternalPrimitiveTypeE.Int64;
  216.                     else if (lxsdType == "language")
  217.                         code = InternalPrimitiveTypeE.Language;
  218.                     break;
  219.                 case 'n':
  220.                     if (lxsdType == "number"//No longer used
  221.                         code = InternalPrimitiveTypeE.Decimal;
  222.                     else if (lxsdType == "normalizedstring")
  223.                         code = InternalPrimitiveTypeE.NormalizedString;
  224.                     else if (lxsdType == "nonpositiveinteger")
  225.                         code = InternalPrimitiveTypeE.NonPositiveInteger;
  226.                     else if (lxsdType == "negativeinteger")
  227.                         code = InternalPrimitiveTypeE.NegativeInteger;
  228.                     else if (lxsdType == "nonnegativeinteger")
  229.                         code = InternalPrimitiveTypeE.NonNegativeInteger;
  230.                     else if (lxsdType == "notation")
  231.                         code = InternalPrimitiveTypeE.Notation;
  232.                     else if (lxsdType == "nmtoken")
  233.                         code = InternalPrimitiveTypeE.Nmtoken;
  234.                     else if (lxsdType == "nmtokens")
  235.                         code = InternalPrimitiveTypeE.Nmtokens;
  236.                     else if (lxsdType == "name")
  237.                         code = InternalPrimitiveTypeE.Name;
  238.                     else if (lxsdType == "ncname")
  239.                         code = InternalPrimitiveTypeE.NcName;
  240.                     break;
  241.                 case 'p':
  242.                     if (lxsdType == "positiveinteger")
  243.                         code = InternalPrimitiveTypeE.PositiveInteger;
  244.                     break;
  245.                 case 'q':
  246.                     if (lxsdType == "qname")
  247.                         code = InternalPrimitiveTypeE.QName;
  248.                     break;
  249.                 case 's':
  250.                     if (lxsdType == "short")
  251.                         code = InternalPrimitiveTypeE.Int16;
  252.                     else if (lxsdType == "system.byte"// used during serialization
  253.                         code = InternalPrimitiveTypeE.Byte;
  254.                     else if (lxsdType == "system.sbyte"// used during serialization
  255.                         code = InternalPrimitiveTypeE.SByte;
  256.                     else if (lxsdType == "system"//used during serialization
  257.                         code = ToCode(value.Substring(7));
  258.                     else if (lxsdType == "system.runtime.remoting.metadata"//used during serialization
  259.                         code = ToCode(value.Substring(33));
  260.                     break;
  261.                 case 't':
  262.                     if (lxsdType == "time")
  263.                         code = InternalPrimitiveTypeE.Time;
  264.                     else if (lxsdType == "token")
  265.                         code = InternalPrimitiveTypeE.Token;
  266.                     else if (lxsdType == "timeinstant")
  267.                         code = InternalPrimitiveTypeE.DateTime;
  268.                     else if (lxsdType == "timeduration")
  269.                         code = InternalPrimitiveTypeE.TimeSpan;
  270.                     break;
  271.                 case 'u':
  272.                     if (lxsdType == "unsignedlong")
  273.                         code = InternalPrimitiveTypeE.UInt64;
  274.                     else if (lxsdType == "unsignedint")
  275.                         code = InternalPrimitiveTypeE.UInt32;
  276.                     else if (lxsdType == "unsignedshort")
  277.                         code = InternalPrimitiveTypeE.UInt16;
  278.                     else if (lxsdType == "unsignedbyte")
  279.                         code = InternalPrimitiveTypeE.Byte;
  280.                     break;
  281.                 default:
  282.                     code = InternalPrimitiveTypeE.Invalid;
  283.                     break;
  284.             }
  285.             InternalST.Soap("Converter""ToCode Exit ", ((Enum)code).ToString());      
  286.             return code;
  287.         }
  288.         internal static bool IsWriteAsByteArray(InternalPrimitiveTypeE code)
  289.         {
  290.             bool isWrite = false;
  291.             switch (code)
  292.             {
  293.                 case InternalPrimitiveTypeE.Boolean:
  294.                 case InternalPrimitiveTypeE.Char:
  295.                 case InternalPrimitiveTypeE.Byte:
  296.                 case InternalPrimitiveTypeE.Double:
  297.                 case InternalPrimitiveTypeE.Int16:
  298.                 case InternalPrimitiveTypeE.Int32:
  299.                 case InternalPrimitiveTypeE.Int64:
  300.                 case InternalPrimitiveTypeE.SByte:
  301.                 case InternalPrimitiveTypeE.Single:
  302.                 case InternalPrimitiveTypeE.UInt16:
  303.                 case InternalPrimitiveTypeE.UInt32:
  304.                 case InternalPrimitiveTypeE.UInt64:
  305.                     isWrite = true;
  306.                     break;
  307.             }
  308.             return isWrite;
  309.         }
  310.         internal static int TypeLength(InternalPrimitiveTypeE code)
  311.         {
  312.             int length  = 0;
  313.             switch (code)
  314.             {
  315.                 case InternalPrimitiveTypeE.Boolean:
  316.                     length = 1;
  317.                     break;
  318.                 case InternalPrimitiveTypeE.Char:
  319.                     length = 2;
  320.                     break;                  
  321.                 case InternalPrimitiveTypeE.Byte:
  322.                     length = 1;
  323.                     break;                  
  324.                 case InternalPrimitiveTypeE.Double:
  325.                     length = 8;
  326.                     break;                  
  327.                 case InternalPrimitiveTypeE.Int16:
  328.                     length = 2;
  329.                     break;                  
  330.                 case InternalPrimitiveTypeE.Int32:
  331.                     length = 4;
  332.                     break;                  
  333.                 case InternalPrimitiveTypeE.Int64:
  334.                     length = 8;
  335.                     break;                  
  336.                 case InternalPrimitiveTypeE.SByte:
  337.                     length = 1;
  338.                     break;                  
  339.                 case InternalPrimitiveTypeE.Single:
  340.                     length = 4;
  341.                     break;                  
  342.                 case InternalPrimitiveTypeE.UInt16:
  343.                     length = 2;
  344.                     break;                  
  345.                 case InternalPrimitiveTypeE.UInt32:
  346.                     length = 4;
  347.                     break;                  
  348.                 case InternalPrimitiveTypeE.UInt64:
  349.                     length = 8;
  350.                     break;                  
  351.             }
  352.             return length;
  353.         }
  354.         internal static InternalNameSpaceE GetNameSpaceEnum(InternalPrimitiveTypeE code, Type type, WriteObjectInfo objectInfo, out String typeName)
  355.         {
  356.             InternalST.Soap("Converter""GetNameSpaceEnum Entry ",((Enum)code).ToString()," type ",type);                  
  357.             InternalNameSpaceE nameSpaceEnum = InternalNameSpaceE.None;
  358.             typeName = null;
  359.             if (code != InternalPrimitiveTypeE.Invalid)
  360.             {
  361.                 if (code == InternalPrimitiveTypeE.Char)
  362.                 {
  363.                     nameSpaceEnum = InternalNameSpaceE.UrtSystem;
  364.                     typeName = "System.Char";
  365.                 }
  366.                 else
  367.                 {
  368.                     nameSpaceEnum = InternalNameSpaceE.XdrPrimitive;
  369.                     typeName = ToXmlDataType(code);
  370.                 }
  371.             }
  372.             if ((nameSpaceEnum == InternalNameSpaceE.None) && (type != null))
  373.             {
  374.                 if (type == typeofString)
  375.                     nameSpaceEnum = InternalNameSpaceE.XdrString;
  376.                 else
  377.                 {
  378.                     if (objectInfo == null)
  379.                     {
  380.                         typeName = type.FullName;
  381.                         if (type.Module.Assembly == urtAssembly)
  382.                             nameSpaceEnum = InternalNameSpaceE.UrtSystem;
  383.                         else
  384.                             nameSpaceEnum = InternalNameSpaceE.UrtUser;                     
  385.                     }
  386.                     else
  387.                     {
  388.                         typeName = objectInfo.GetTypeFullName();
  389.                         // If objref is created from a proxy, it will have the proxy namespace
  390.                         // Need to force ObjRef to have system namespace
  391.                         if (objectInfo.GetAssemblyString().Equals(urtAssemblyString))
  392.                             nameSpaceEnum = InternalNameSpaceE.UrtSystem;
  393.                         else
  394.                             nameSpaceEnum = InternalNameSpaceE.UrtUser;
  395.                     }
  396.                 }
  397.             }
  398.             // If there is an explicitly specified namespace, then it is used
  399.             if (objectInfo != null)
  400.             {
  401.                 if (!objectInfo.isSi &
  402.                     (objectInfo.IsAttributeNameSpace() ||
  403.                     objectInfo.IsCustomXmlAttribute() ||
  404.                     objectInfo.IsCustomXmlElement()))
  405.                 {
  406.                     nameSpaceEnum = InternalNameSpaceE.Interop;
  407.                 }
  408.                 else if (objectInfo.IsCallElement())
  409.                 {
  410.                     nameSpaceEnum = InternalNameSpaceE.CallElement;
  411.                 }
  412.             }
  413.             InternalST.Soap("Converter""GetNameSpaceEnum Exit ", ((Enum)nameSpaceEnum).ToString()," typeName ",typeName);                             
  414.             return nameSpaceEnum;
  415.         }
  416.         // Primitive types for which types need to be transmitted in Soap for ISerialable
  417.         internal static bool IsSiTransmitType(InternalPrimitiveTypeE code)
  418.         {
  419.             switch (code)
  420.             {
  421.                 case InternalPrimitiveTypeE.TimeSpan:
  422.                 case InternalPrimitiveTypeE.DateTime:
  423.                 case InternalPrimitiveTypeE.Time:
  424.                 case InternalPrimitiveTypeE.Date:
  425.                 case InternalPrimitiveTypeE.YearMonth:
  426.                 case InternalPrimitiveTypeE.Year:
  427.                 case InternalPrimitiveTypeE.MonthDay:
  428.                 case InternalPrimitiveTypeE.Day:
  429.                 case InternalPrimitiveTypeE.Month:
  430.                 case InternalPrimitiveTypeE.HexBinary:
  431.                 case InternalPrimitiveTypeE.Base64Binary:
  432.                 case InternalPrimitiveTypeE.Integer:
  433.                 case InternalPrimitiveTypeE.PositiveInteger:
  434.                 case InternalPrimitiveTypeE. NonPositiveInteger:
  435.                 case InternalPrimitiveTypeE.NonNegativeInteger:
  436.                 case InternalPrimitiveTypeE.NegativeInteger:
  437.                 case InternalPrimitiveTypeE.AnyUri:
  438.                 case InternalPrimitiveTypeE.QName:
  439.                 case InternalPrimitiveTypeE.Notation:
  440.                 case InternalPrimitiveTypeE.NormalizedString:
  441.                 case InternalPrimitiveTypeE.Token:
  442.                 case InternalPrimitiveTypeE.Language:
  443.                 case InternalPrimitiveTypeE.Name:
  444.                 case InternalPrimitiveTypeE.Idrefs:
  445.                 case InternalPrimitiveTypeE.Entities:
  446.                 case InternalPrimitiveTypeE.Nmtoken:
  447.                 case InternalPrimitiveTypeE.Nmtokens:
  448.                 case InternalPrimitiveTypeE.NcName:
  449.                 case InternalPrimitiveTypeE.Id:
  450.                 case InternalPrimitiveTypeE.Idref:
  451.                 case InternalPrimitiveTypeE.Entity:
  452.                 case InternalPrimitiveTypeE.Invalid:                    
  453.                     return true;
  454.                 default:
  455.                     return false;
  456.             }
  457.         }
  458.         private static Type[] typeA;
  459.         private static void InitTypeA()
  460.         {
  461.             typeA = new Type[primitiveTypeEnumLength];
  462.             typeA[(int)InternalPrimitiveTypeE.Invalid] = null;
  463.             typeA[(int)InternalPrimitiveTypeE.Boolean] = typeofBoolean;
  464.             typeA[(int)InternalPrimitiveTypeE.Byte] = typeofByte;
  465.             typeA[(int)InternalPrimitiveTypeE.Char] = typeofChar;
  466.             typeA[(int)InternalPrimitiveTypeE.Decimal] = typeofDecimal;
  467.             typeA[(int)InternalPrimitiveTypeE.Double] = typeofDouble;
  468.             typeA[(int)InternalPrimitiveTypeE.Int16] = typeofInt16;
  469.             typeA[(int)InternalPrimitiveTypeE.Int32] = typeofInt32;
  470.             typeA[(int)InternalPrimitiveTypeE.Int64] = typeofInt64;
  471.             typeA[(int)InternalPrimitiveTypeE.SByte] = typeofSByte;
  472.             typeA[(int)InternalPrimitiveTypeE.Single] = typeofSingle;
  473.             typeA[(int)InternalPrimitiveTypeE.TimeSpan] = typeofTimeSpan;
  474.             typeA[(int)InternalPrimitiveTypeE.DateTime] = typeofDateTime;
  475.             typeA[(int)InternalPrimitiveTypeE.UInt16] = typeofUInt16;
  476.             typeA[(int)InternalPrimitiveTypeE.UInt32] = typeofUInt32;
  477.             typeA[(int)InternalPrimitiveTypeE.UInt64] = typeofUInt64;
  478.             typeA[(int)InternalPrimitiveTypeE.Time] = typeofSoapTime;
  479.             typeA[(int)InternalPrimitiveTypeE.Date] = typeofSoapDate;
  480.             typeA[(int)InternalPrimitiveTypeE.YearMonth] = typeofSoapYearMonth;
  481.             typeA[(int)InternalPrimitiveTypeE.Year] = typeofSoapYear;
  482.             typeA[(int)InternalPrimitiveTypeE.MonthDay] = typeofSoapMonthDay;
  483.             typeA[(int)InternalPrimitiveTypeE.Day] = typeofSoapDay;
  484.             typeA[(int)InternalPrimitiveTypeE.Month] = typeofSoapMonth;
  485.             typeA[(int)InternalPrimitiveTypeE.HexBinary] = typeofSoapHexBinary;
  486.             typeA[(int)InternalPrimitiveTypeE.Base64Binary] = typeofSoapBase64Binary;
  487.             typeA[(int)InternalPrimitiveTypeE.Integer] = typeofSoapInteger;
  488.             typeA[(int)InternalPrimitiveTypeE.PositiveInteger] = typeofSoapPositiveInteger;
  489.             typeA[(int)InternalPrimitiveTypeE.NonPositiveInteger] = typeofSoapNonPositiveInteger;
  490.             typeA[(int)InternalPrimitiveTypeE.NonNegativeInteger] = typeofSoapNonNegativeInteger;
  491.             typeA[(int)InternalPrimitiveTypeE.NegativeInteger] = typeofSoapNegativeInteger;
  492.             typeA[(int)InternalPrimitiveTypeE.AnyUri] = typeofSoapAnyUri;
  493.             typeA[(int)InternalPrimitiveTypeE.QName] = typeofSoapQName;
  494.             typeA[(int)InternalPrimitiveTypeE.Notation] = typeofSoapNotation;
  495.             typeA[(int)InternalPrimitiveTypeE.NormalizedString] = typeofSoapNormalizedString;
  496.             typeA[(int)InternalPrimitiveTypeE.Token] = typeofSoapToken;
  497.             typeA[(int)InternalPrimitiveTypeE.Language] = typeofSoapLanguage;
  498.             typeA[(int)InternalPrimitiveTypeE.Name] = typeofSoapName;
  499.             typeA[(int)InternalPrimitiveTypeE.Idrefs] = typeofSoapIdrefs;
  500.             typeA[(int)InternalPrimitiveTypeE.Entities] = typeofSoapEntities;
  501.             typeA[(int)InternalPrimitiveTypeE.Nmtoken] = typeofSoapNmtoken;
  502.             typeA[(int)InternalPrimitiveTypeE.Nmtokens] = typeofSoapNmtokens;
  503.             typeA[(int)InternalPrimitiveTypeE.NcName] = typeofSoapNcName;
  504.             typeA[(int)InternalPrimitiveTypeE.Id] = typeofSoapId;
  505.             typeA[(int)InternalPrimitiveTypeE.Idref] = typeofSoapIdref;
  506.             typeA[(int)InternalPrimitiveTypeE.Entity] = typeofSoapEntity;
  507.         }
  508.         // Returns a COM runtime type associated with the type  code
  509.         internal static Type SoapToType(InternalPrimitiveTypeE code)
  510.         {
  511.             return ToType(code);
  512.         }
  513.         internal static Type ToType(InternalPrimitiveTypeE code)
  514.         {
  515.             InternalST.Soap("Converter""ToType Entry ", ((Enum)code).ToString());
  516.             lock(typeofConverter)
  517.             {
  518.                 if (typeA == null)
  519.                     InitTypeA();
  520.             }
  521.             InternalST.Soap("Converter""ToType Exit ", ((typeA[(int)code] == null)?"null ":typeA[(int)code].Name));               
  522.             return typeA[(int)code];
  523.         }
  524.         private static String[] valueA;
  525.         private static void InitValueA()
  526.         {
  527.             valueA = new String[primitiveTypeEnumLength];
  528.             valueA[(int)InternalPrimitiveTypeE.Invalid] = null;
  529.             valueA[(int)InternalPrimitiveTypeE.Boolean] = "System.Boolean";
  530.             valueA[(int)InternalPrimitiveTypeE.Byte] = "System.Byte";
  531.             valueA[(int)InternalPrimitiveTypeE.Char] = "System.Char";
  532.             valueA[(int)InternalPrimitiveTypeE.Decimal] = "System.Decimal";
  533.             valueA[(int)InternalPrimitiveTypeE.Double] = "System.Double";
  534.             valueA[(int)InternalPrimitiveTypeE.Int16] = "System.Int16";
  535.             valueA[(int)InternalPrimitiveTypeE.Int32] = "System.Int32";
  536.             valueA[(int)InternalPrimitiveTypeE.Int64] = "System.Int64";
  537.             valueA[(int)InternalPrimitiveTypeE.SByte] = "System.SByte";
  538.             valueA[(int)InternalPrimitiveTypeE.Single] = "System.Single";
  539.             valueA[(int)InternalPrimitiveTypeE.TimeSpan] = "System.TimeSpan";
  540.             valueA[(int)InternalPrimitiveTypeE.DateTime] = "System.DateTime";
  541.             valueA[(int)InternalPrimitiveTypeE.UInt16] = "System.UInt16";
  542.             valueA[(int)InternalPrimitiveTypeE.UInt32] = "System.UInt32";
  543.             valueA[(int)InternalPrimitiveTypeE.UInt64] = "System.UInt64"
  544.             valueA[(int)InternalPrimitiveTypeE.Time] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapTime";
  545.             valueA[(int)InternalPrimitiveTypeE.Date] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDate";
  546.             valueA[(int)InternalPrimitiveTypeE.YearMonth] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapYearMonth";
  547.             valueA[(int)InternalPrimitiveTypeE.Year] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapYear";
  548.             valueA[(int)InternalPrimitiveTypeE.MonthDay] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapMonthDay";
  549.             valueA[(int)InternalPrimitiveTypeE.Day] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDay";
  550.             valueA[(int)InternalPrimitiveTypeE.Month] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapMonth";
  551.             valueA[(int)InternalPrimitiveTypeE.HexBinary] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary";
  552.             valueA[(int)InternalPrimitiveTypeE.Base64Binary] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapBase64Binary";
  553.             valueA[(int)InternalPrimitiveTypeE.Integer] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapInteger";
  554.             valueA[(int)InternalPrimitiveTypeE.PositiveInteger] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapPositiveInteger";
  555.             valueA[(int)InternalPrimitiveTypeE.NonPositiveInteger] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNonPositiveInteger";
  556.             valueA[(int)InternalPrimitiveTypeE.NonNegativeInteger] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNonNegativeInteger";
  557.             valueA[(int)InternalPrimitiveTypeE.NegativeInteger] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNegativeInteger";
  558.             valueA[(int)InternalPrimitiveTypeE.AnyUri] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapAnyUri";
  559.             valueA[(int)InternalPrimitiveTypeE.QName] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapQName";
  560.             valueA[(int)InternalPrimitiveTypeE.Notation] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNotation";
  561.             valueA[(int)InternalPrimitiveTypeE.NormalizedString] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNormalizedString";
  562.             valueA[(int)InternalPrimitiveTypeE.Token] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapToken";
  563.             valueA[(int)InternalPrimitiveTypeE.Language] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapLanguage";
  564.             valueA[(int)InternalPrimitiveTypeE.Name] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapName";
  565.             valueA[(int)InternalPrimitiveTypeE.Idrefs] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapIdrefs";
  566.             valueA[(int)InternalPrimitiveTypeE.Entities] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapEntities";
  567.             valueA[(int)InternalPrimitiveTypeE.Nmtoken] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNmtoken";
  568.             valueA[(int)InternalPrimitiveTypeE.Nmtokens] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNmtokens";
  569.             valueA[(int)InternalPrimitiveTypeE.NcName] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNcName";
  570.             valueA[(int)InternalPrimitiveTypeE.Id] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapId";
  571.             valueA[(int)InternalPrimitiveTypeE.Idref] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapIdref";
  572.             valueA[(int)InternalPrimitiveTypeE.Entity] = "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapEntity";
  573.         }
  574.         // Returns a String containg a COM+ runtime type associated with the type code
  575.         internal static String SoapToComType(InternalPrimitiveTypeE code)
  576.         {
  577.             return ToComType(code);
  578.         }
  579.         internal static String ToComType(InternalPrimitiveTypeE code)
  580.         {
  581.             InternalST.Soap("Converter""ToComType Entry ", ((Enum)code).ToString());
  582.             lock(typeofConverter)
  583.             {
  584.                 if (valueA == null)
  585.                     InitValueA();
  586.             }
  587.             InternalST.Soap("Converter""ToComType Exit ",((valueA[(int)code] == null)?"null":valueA[(int)code]));             
  588.             return valueA[(int)code];
  589.         }
  590.         private static String[] valueB;
  591.         private static void InitValueB()
  592.         {
  593.             valueB = new String[primitiveTypeEnumLength];
  594.             valueB[(int)InternalPrimitiveTypeE.Invalid] = null;
  595.             valueB[(int)InternalPrimitiveTypeE.Boolean] = "boolean";
  596.             valueB[(int)InternalPrimitiveTypeE.Byte] = "unsignedByte";
  597.             valueB[(int)InternalPrimitiveTypeE.Char] = "char"//not an xsi type, but will cause problems with clr if char is not used
  598.             valueB[(int)InternalPrimitiveTypeE.Decimal] = "decimal";
  599.             valueB[(int)InternalPrimitiveTypeE.Double] = "double";
  600.             valueB[(int)InternalPrimitiveTypeE.Int16] = "short";
  601.             valueB[(int)InternalPrimitiveTypeE.Int32] = "int";
  602.             valueB[(int)InternalPrimitiveTypeE.Int64] = "long";
  603.             valueB[(int)InternalPrimitiveTypeE.SByte] = "byte";
  604.             valueB[(int)InternalPrimitiveTypeE.Single] = "float";
  605.             valueB[(int)InternalPrimitiveTypeE.TimeSpan] = "duration";
  606.             valueB[(int)InternalPrimitiveTypeE.DateTime] = "dateTime";
  607.             valueB[(int)InternalPrimitiveTypeE.UInt16] = "unsignedShort";
  608.             valueB[(int)InternalPrimitiveTypeE.UInt32] = "unsignedInt";
  609.             valueB[(int)InternalPrimitiveTypeE.UInt64] = "unsignedLong"
  610.             valueB[(int)InternalPrimitiveTypeE.Time] = SoapTime.XsdType;
  611.             valueB[(int)InternalPrimitiveTypeE.Date] = SoapDate.XsdType;
  612.             valueB[(int)InternalPrimitiveTypeE.YearMonth] = SoapYearMonth.XsdType;
  613.             valueB[(int)InternalPrimitiveTypeE.Year] = SoapYear.XsdType;
  614.             valueB[(int)InternalPrimitiveTypeE.MonthDay] = SoapMonthDay.XsdType;
  615.             valueB[(int)InternalPrimitiveTypeE.Day] = SoapDay.XsdType;
  616.             valueB[(int)InternalPrimitiveTypeE.Month] = SoapMonth.XsdType;
  617.             valueB[(int)InternalPrimitiveTypeE.HexBinary] = SoapHexBinary.XsdType;
  618.             valueB[(int)InternalPrimitiveTypeE.Base64Binary] = SoapBase64Binary.XsdType;
  619.             valueB[(int)InternalPrimitiveTypeE.Integer] = SoapInteger.XsdType;
  620.             valueB[(int)InternalPrimitiveTypeE.PositiveInteger] = SoapPositiveInteger.XsdType;
  621.             valueB[(int)InternalPrimitiveTypeE.NonPositiveInteger] = SoapNonPositiveInteger.XsdType;
  622.             valueB[(int)InternalPrimitiveTypeE.NonNegativeInteger] = SoapNonNegativeInteger.XsdType;
  623.             valueB[(int)InternalPrimitiveTypeE.NegativeInteger] = SoapNegativeInteger.XsdType;
  624.             valueB[(int)InternalPrimitiveTypeE.AnyUri] = SoapAnyUri.XsdType;
  625.             valueB[(int)InternalPrimitiveTypeE.QName] = SoapQName.XsdType;
  626.             valueB[(int)InternalPrimitiveTypeE.Notation] = SoapNotation.XsdType;
  627.             valueB[(int)InternalPrimitiveTypeE.NormalizedString] = SoapNormalizedString.XsdType;
  628.             valueB[(int)InternalPrimitiveTypeE.Token] = SoapToken.XsdType;
  629.             valueB[(int)InternalPrimitiveTypeE.Language] = SoapLanguage.XsdType;
  630.             valueB[(int)InternalPrimitiveTypeE.Name] = SoapName.XsdType;
  631.             valueB[(int)InternalPrimitiveTypeE.Idrefs] = SoapIdrefs.XsdType;
  632.             valueB[(int)InternalPrimitiveTypeE.Entities] = SoapEntities.XsdType;
  633.             valueB[(int)InternalPrimitiveTypeE.Nmtoken] = SoapNmtoken.XsdType;
  634.             valueB[(int)InternalPrimitiveTypeE.Nmtokens] = SoapNmtokens.XsdType;
  635.             valueB[(int)InternalPrimitiveTypeE.NcName] = SoapNcName.XsdType;
  636.             valueB[(int)InternalPrimitiveTypeE.Id] = SoapId.XsdType;
  637.             valueB[(int)InternalPrimitiveTypeE.Idref] = SoapIdref.XsdType;
  638.             valueB[(int)InternalPrimitiveTypeE.Entity] = SoapEntity.XsdType;
  639.         }
  640.         // Returns a String containg an XML Data type associated with the type code
  641.         internal static String ToXmlDataType(InternalPrimitiveTypeE code)
  642.         {
  643.             InternalST.Soap( "Converter""ToXmlDataType Entry ", ((Enum)code).ToString());     
  644.             lock(typeofConverter)
  645.             {
  646.                 if (valueB == null)
  647.                     InitValueB();
  648.             }
  649.             InternalST.Soap( "Converter""ToXmlDataType Exit ",((valueB[(int)code] == null)?"null":valueB[(int)code]));                
  650.             return valueB[(int)code];
  651.         }
  652.         private static TypeCode[] typeCodeA;
  653.         private static void InitTypeCodeA()
  654.         {
  655.             typeCodeA = new TypeCode[primitiveTypeEnumLength];
  656.             typeCodeA[(int)InternalPrimitiveTypeE.Invalid] = TypeCode.Object;
  657.             typeCodeA[(int)InternalPrimitiveTypeE.Boolean] = TypeCode.Boolean;
  658.             typeCodeA[(int)InternalPrimitiveTypeE.Byte] = TypeCode.Byte;
  659.             typeCodeA[(int)InternalPrimitiveTypeE.Char] = TypeCode.Char;
  660.             typeCodeA[(int)InternalPrimitiveTypeE.Decimal] = TypeCode.Decimal;
  661.             typeCodeA[(int)InternalPrimitiveTypeE.Double] = TypeCode.Double;
  662.             typeCodeA[(int)InternalPrimitiveTypeE.Int16] = TypeCode.Int16;
  663.             typeCodeA[(int)InternalPrimitiveTypeE.Int32] = TypeCode.Int32;
  664.             typeCodeA[(int)InternalPrimitiveTypeE.Int64] = TypeCode.Int64;
  665.             typeCodeA[(int)InternalPrimitiveTypeE.SByte] = TypeCode.SByte;
  666.             typeCodeA[(int)InternalPrimitiveTypeE.Single] = TypeCode.Single;
  667.             typeCodeA[(int)InternalPrimitiveTypeE.TimeSpan] = TypeCode.Object;
  668.             typeCodeA[(int)InternalPrimitiveTypeE.DateTime] = TypeCode.DateTime;
  669.             typeCodeA[(int)InternalPrimitiveTypeE.UInt16] = TypeCode.UInt16;
  670.             typeCodeA[(int)InternalPrimitiveTypeE.UInt32] = TypeCode.UInt32;
  671.             typeCodeA[(int)InternalPrimitiveTypeE.UInt64] = TypeCode.UInt64;
  672.             typeCodeA[(int)InternalPrimitiveTypeE.Time] = TypeCode.Object;
  673.             typeCodeA[(int)InternalPrimitiveTypeE.Date] = TypeCode.Object;
  674.             typeCodeA[(int)InternalPrimitiveTypeE.YearMonth] = TypeCode.Object;
  675.             typeCodeA[(int)InternalPrimitiveTypeE.Year] = TypeCode.Object;
  676.             typeCodeA[(int)InternalPrimitiveTypeE.MonthDay] = TypeCode.Object;
  677.             typeCodeA[(int)InternalPrimitiveTypeE.Day] = TypeCode.Object;
  678.             typeCodeA[(int)InternalPrimitiveTypeE.Month] = TypeCode.Object;
  679.             typeCodeA[(int)InternalPrimitiveTypeE.HexBinary] = TypeCode.Object;
  680.             typeCodeA[(int)InternalPrimitiveTypeE.Base64Binary] = TypeCode.Object;
  681.             typeCodeA[(int)InternalPrimitiveTypeE.Integer] = TypeCode.Object;
  682.             typeCodeA[(int)InternalPrimitiveTypeE.PositiveInteger] = TypeCode.Object;
  683.             typeCodeA[(int)InternalPrimitiveTypeE.NonPositiveInteger] = TypeCode.Object;
  684.             typeCodeA[(int)InternalPrimitiveTypeE.NonNegativeInteger] = TypeCode.Object;
  685.             typeCodeA[(int)InternalPrimitiveTypeE.NegativeInteger] = TypeCode.Object;
  686.             typeCodeA[(int)InternalPrimitiveTypeE.AnyUri] = TypeCode.Object;
  687.             typeCodeA[(int)InternalPrimitiveTypeE.QName] = TypeCode.Object;
  688.             typeCodeA[(int)InternalPrimitiveTypeE.Notation] = TypeCode.Object;
  689.             typeCodeA[(int)InternalPrimitiveTypeE.NormalizedString] = TypeCode.Object;
  690.             typeCodeA[(int)InternalPrimitiveTypeE.Token] = TypeCode.Object;
  691.             typeCodeA[(int)InternalPrimitiveTypeE.Language] = TypeCode.Object;
  692.             typeCodeA[(int)InternalPrimitiveTypeE.Name] = TypeCode.Object;
  693.             typeCodeA[(int)InternalPrimitiveTypeE.Idrefs] = TypeCode.Object;
  694.             typeCodeA[(int)InternalPrimitiveTypeE.Entities] = TypeCode.Object;
  695.             typeCodeA[(int)InternalPrimitiveTypeE.Nmtoken] = TypeCode.Object;
  696.             typeCodeA[(int)InternalPrimitiveTypeE.Nmtokens] = TypeCode.Object;
  697.             typeCodeA[(int)InternalPrimitiveTypeE.NcName] = TypeCode.Object;
  698.             typeCodeA[(int)InternalPrimitiveTypeE.Id] = TypeCode.Object;
  699.             typeCodeA[(int)InternalPrimitiveTypeE.Idref] = TypeCode.Object;
  700.             typeCodeA[(int)InternalPrimitiveTypeE.Entity] = TypeCode.Object;
  701.         }
  702.         // Returns a System.TypeCode from a InternalPrimitiveTypeE
  703.         internal static TypeCode ToTypeCode(InternalPrimitiveTypeE code)
  704.         {
  705.             lock(typeofConverter)
  706.             {
  707.                 if (typeCodeA == null)
  708.                     InitTypeCodeA();
  709.             }
  710.             return typeCodeA[(int)code];
  711.         }
  712.         private static InternalPrimitiveTypeE[] codeA;
  713.         private static void InitCodeA()
  714.         {
  715.             codeA = new InternalPrimitiveTypeE[19];
  716.             codeA[(int)TypeCode.Empty] = InternalPrimitiveTypeE.Invalid;
  717.             codeA[(int)TypeCode.Object] = InternalPrimitiveTypeE.Invalid;
  718.             codeA[(int)TypeCode.DBNull] = InternalPrimitiveTypeE.Invalid;                   
  719.             codeA[(int)TypeCode.Boolean] = InternalPrimitiveTypeE.Boolean;
  720.             codeA[(int)TypeCode.Char] = InternalPrimitiveTypeE.Char;
  721.             codeA[(int)TypeCode.SByte] = InternalPrimitiveTypeE.SByte;
  722.             codeA[(int)TypeCode.Byte] = InternalPrimitiveTypeE.Byte;
  723.             codeA[(int)TypeCode.Int16] = InternalPrimitiveTypeE.Int16;
  724.             codeA[(int)TypeCode.UInt16] = InternalPrimitiveTypeE.UInt16;
  725.             codeA[(int)TypeCode.Int32] = InternalPrimitiveTypeE.Int32;
  726.             codeA[(int)TypeCode.UInt32] = InternalPrimitiveTypeE.UInt32;
  727.             codeA[(int)TypeCode.Int64] = InternalPrimitiveTypeE.Int64;
  728.             codeA[(int)TypeCode.UInt64] = InternalPrimitiveTypeE.UInt64;
  729.             codeA[(int)TypeCode.Single] = InternalPrimitiveTypeE.Single;
  730.             codeA[(int)TypeCode.Double] = InternalPrimitiveTypeE.Double;
  731.             codeA[(int)TypeCode.Decimal] = InternalPrimitiveTypeE.Decimal;
  732.             codeA[(int)TypeCode.DateTime] = InternalPrimitiveTypeE.DateTime;
  733.             codeA[17] = InternalPrimitiveTypeE.Invalid;
  734.             codeA[(int)TypeCode.String] = InternalPrimitiveTypeE.Invalid;                                       
  735.             //codeA[(int)TypeCode.TimeSpan] = InternalPrimitiveTypeE.TimeSpan;
  736.         }
  737.         // Returns a InternalPrimitiveTypeE from a System.TypeCode
  738.         internal static InternalPrimitiveTypeE ToPrimitiveTypeEnum(TypeCode typeCode)
  739.         {
  740.             lock(typeofConverter)
  741.             {
  742.                 if (codeA == null)
  743.                     InitCodeA();
  744.             }
  745.             return codeA[(int)typeCode];
  746.         }
  747.         //********************
  748.         private static bool[] escapeA;
  749.         private static void InitEscapeA()
  750.         {
  751.             escapeA = new bool[primitiveTypeEnumLength];
  752.             escapeA[(int)InternalPrimitiveTypeE.Invalid] = true;
  753.             escapeA[(int)InternalPrimitiveTypeE.Boolean] = false;
  754.             escapeA[(int)InternalPrimitiveTypeE.Byte] = false;
  755.             escapeA[(int)InternalPrimitiveTypeE.Char] = true;
  756.             escapeA[(int)InternalPrimitiveTypeE.Decimal] = false;
  757.             escapeA[(int)InternalPrimitiveTypeE.Double] = false;
  758.             escapeA[(int)InternalPrimitiveTypeE.Int16] = false;
  759.             escapeA[(int)InternalPrimitiveTypeE.Int32] = false;
  760.             escapeA[(int)InternalPrimitiveTypeE.Int64] = false;
  761.             escapeA[(int)InternalPrimitiveTypeE.SByte] = false;
  762.             escapeA[(int)InternalPrimitiveTypeE.Single] = false;
  763.             escapeA[(int)InternalPrimitiveTypeE.TimeSpan] = false;
  764.             escapeA[(int)InternalPrimitiveTypeE.DateTime] = false;
  765.             escapeA[(int)InternalPrimitiveTypeE.UInt16] = false;
  766.             escapeA[(int)InternalPrimitiveTypeE.UInt32] = false;
  767.             escapeA[(int)InternalPrimitiveTypeE.UInt64] = false;
  768.             escapeA[(int)InternalPrimitiveTypeE.Time] = false;
  769.             escapeA[(int)InternalPrimitiveTypeE.Date] = false;
  770.             escapeA[(int)InternalPrimitiveTypeE.YearMonth] = false;
  771.             escapeA[(int)InternalPrimitiveTypeE.Year] = false;
  772.             escapeA[(int)InternalPrimitiveTypeE.MonthDay] = false;
  773.             escapeA[(int)InternalPrimitiveTypeE.Day] = false;
  774.             escapeA[(int)InternalPrimitiveTypeE.Month] = false;
  775.             escapeA[(int)InternalPrimitiveTypeE.HexBinary] = false;
  776.             escapeA[(int)InternalPrimitiveTypeE.Base64Binary] = false;
  777.             escapeA[(int)InternalPrimitiveTypeE.Integer] = false;
  778.             escapeA[(int)InternalPrimitiveTypeE.PositiveInteger] = false;
  779.             escapeA[(int)InternalPrimitiveTypeE.NonPositiveInteger] = false;
  780.             escapeA[(int)InternalPrimitiveTypeE.NonNegativeInteger] = false;
  781.             escapeA[(int)InternalPrimitiveTypeE.NegativeInteger] = false;
  782.             escapeA[(int)InternalPrimitiveTypeE.AnyUri] = true;
  783.             escapeA[(int)InternalPrimitiveTypeE.QName] = true;
  784.             escapeA[(int)InternalPrimitiveTypeE.Notation] = true;
  785.             escapeA[(int)InternalPrimitiveTypeE.NormalizedString] = false;
  786.             escapeA[(int)InternalPrimitiveTypeE.Token] = true;
  787.             escapeA[(int)InternalPrimitiveTypeE.Language] = true;
  788.             escapeA[(int)InternalPrimitiveTypeE.Name] = true;
  789.             escapeA[(int)InternalPrimitiveTypeE.Idrefs] = true;
  790.             escapeA[(int)InternalPrimitiveTypeE.Entities] = true;
  791.             escapeA[(int)InternalPrimitiveTypeE.Nmtoken] = true;
  792.             escapeA[(int)InternalPrimitiveTypeE.Nmtokens] = true;
  793.             escapeA[(int)InternalPrimitiveTypeE.NcName] = true;
  794.             escapeA[(int)InternalPrimitiveTypeE.Id] = true;
  795.             escapeA[(int)InternalPrimitiveTypeE.Idref] = true;
  796.             escapeA[(int)InternalPrimitiveTypeE.Entity] = true;
  797.         }
  798.         // Checks if the string is escaped (XML escape characters)
  799.         internal static bool IsEscaped(InternalPrimitiveTypeE code)
  800.         {
  801.             lock(typeofConverter)
  802.             {
  803.                 if (escapeA == null)
  804.                     InitEscapeA();
  805.             }
  806.             return escapeA[(int)code];
  807.         }
  808.         // Translates an Object into a string with the COM+ runtime type name
  809.         private static StringBuilder sb = new StringBuilder(30);
  810.         internal static String SoapToString(Object data, InternalPrimitiveTypeE code)
  811.         {
  812.             return ToString(data, code);
  813.         }
  814.         internal static String ToString(Object data, InternalPrimitiveTypeE code)
  815.         {
  816.             // Any changes here need to also be made in System.Runtime.Remoting.Message.cs::SoapCoerceArg
  817.             String value;
  818.             InternalST.Soap( "Converter""ToString Entry ", ((data==null)?"<null>":data.GetType().ToString())," ",data," " , ((Enum)code).ToString());
  819.             switch (code)
  820.             {
  821.                 case InternalPrimitiveTypeE.Boolean:
  822.                     bool b = (bool)data;
  823.                     if (b)
  824.                         value = "true";
  825.                     else
  826.                         value = "false";
  827.                     break;
  828.                 case InternalPrimitiveTypeE.TimeSpan:
  829.                     value = SoapDuration.ToString((TimeSpan)data);
  830.                     break;                          
  831.                 case InternalPrimitiveTypeE.DateTime:
  832.                     value = SoapDateTime.ToString((DateTime)data);
  833.                     break;
  834.                 case InternalPrimitiveTypeE.Invalid:
  835.                     // ToString should not be called if data is an object or string
  836.                     InternalST.SoapAssert(false"[Converter.ToString]!InternalPrimitiveTypeE.Invalid ");
  837.                     value = data.ToString();
  838.                     break;
  839.                 case InternalPrimitiveTypeE.Double:
  840.                     Double doublevalue = (Double)data;
  841.                     if (Double.IsPositiveInfinity(doublevalue))
  842.                         value = "INF";
  843.                     else if (Double.IsNegativeInfinity(doublevalue))
  844.                         value = "-INF";
  845.                     else
  846.                         value = doublevalue.ToString("R", CultureInfo.InvariantCulture);
  847.                     break;
  848.                 case InternalPrimitiveTypeE.Single:
  849.                     Single singlevalue = (Single)data;
  850.                     if (Single.IsPositiveInfinity(singlevalue))
  851.                         value = "INF";
  852.                     else if (Single.IsNegativeInfinity(singlevalue))
  853.                         value = "-INF";
  854.                     else
  855.                         value = singlevalue.ToString("R", CultureInfo.InvariantCulture);
  856.                     break
  857.                 case InternalPrimitiveTypeE.Time:
  858.                 case InternalPrimitiveTypeE.Date:
  859.                 case InternalPrimitiveTypeE.YearMonth:
  860.                 case InternalPrimitiveTypeE.Year:
  861.                 case InternalPrimitiveTypeE.MonthDay:
  862.                 case InternalPrimitiveTypeE.Day:
  863.                 case InternalPrimitiveTypeE.Month:
  864.                 case InternalPrimitiveTypeE.HexBinary:
  865.                 case InternalPrimitiveTypeE.Base64Binary:
  866.                 case InternalPrimitiveTypeE.Integer:
  867.                 case InternalPrimitiveTypeE.PositiveInteger:
  868.                 case InternalPrimitiveTypeE. NonPositiveInteger:
  869.                 case InternalPrimitiveTypeE.NonNegativeInteger:
  870.                 case InternalPrimitiveTypeE.NegativeInteger:
  871.                 case InternalPrimitiveTypeE.AnyUri:
  872.                 case InternalPrimitiveTypeE.QName:
  873.                 case InternalPrimitiveTypeE.Notation:
  874.                 case InternalPrimitiveTypeE.NormalizedString:
  875.                 case InternalPrimitiveTypeE.Token:
  876.                 case InternalPrimitiveTypeE.Language:
  877.                 case InternalPrimitiveTypeE.Name:
  878.                 case InternalPrimitiveTypeE.Idrefs:
  879.                 case InternalPrimitiveTypeE.Entities:
  880.                 case InternalPrimitiveTypeE.Nmtoken:
  881.                 case InternalPrimitiveTypeE.Nmtokens:
  882.                 case InternalPrimitiveTypeE.NcName:
  883.                 case InternalPrimitiveTypeE.Id:
  884.                 case InternalPrimitiveTypeE.Idref:
  885.                 case InternalPrimitiveTypeE.Entity:
  886.                         value = data.ToString();
  887.                         break;
  888.                 default:
  889.                     value = (String)Convert.ChangeType(data, typeofString, CultureInfo.InvariantCulture);
  890.                     break;
  891.             }
  892.             InternalST.Soap( "Converter""ToString Exit ",value);          
  893.             return value;
  894.         }
  895.         // Translates a string into an Object
  896.         internal static Object FromString(String value, InternalPrimitiveTypeE code)
  897.         {
  898.             Object var;
  899.             InternalST.Soap( "Converter""FromString Entry ",value," " , ((Enum)code).ToString());             
  900.             switch (code)
  901.             {
  902.                 case InternalPrimitiveTypeE.Boolean:
  903.                     if (value == "1" || value == "true")
  904.                         var = (bool)true;
  905.                     else if (value == "0" || value =="false")
  906.                         var = (bool)false;
  907.                     else
  908.                         throw new SerializationException(String.Format(SoapUtil.GetResourceString("Serialization_typeCoercion"),value, "Boolean"));                                                                                
  909.                     break;
  910.                 case InternalPrimitiveTypeE.TimeSpan:
  911.                     var = SoapDuration.Parse(value);
  912.                     break;                          
  913.                 case InternalPrimitiveTypeE.DateTime:
  914.                     var = SoapDateTime.Parse(value);
  915.                     break;   
  916.                 case InternalPrimitiveTypeE.Double:
  917.                     if (value == "INF")
  918.                         var =  Double.PositiveInfinity;
  919.                     else if (value == "-INF")
  920.                         var =  Double.NegativeInfinity;
  921.                     else
  922.                         var = Double.Parse(value, CultureInfo.InvariantCulture);
  923.                     break;
  924.                 case InternalPrimitiveTypeE.Single:
  925.                     if (value == "INF")
  926.                         var =  Single.PositiveInfinity;
  927.                     else if (value == "-INF")
  928.                         var =  Single.NegativeInfinity;
  929.                     else
  930.                         var = Single.Parse(value, CultureInfo.InvariantCulture);
  931.                     break;
  932.                 case InternalPrimitiveTypeE.Time:
  933.                     var= SoapTime.Parse(value);
  934.                     break
  935.                 case InternalPrimitiveTypeE.Date:
  936.                     var= SoapDate.Parse(value);
  937.                     break
  938.                 case InternalPrimitiveTypeE.YearMonth:
  939.                     var= SoapYearMonth.Parse(value);
  940.                     break
  941.                 case InternalPrimitiveTypeE.Year:
  942.                     var= SoapYear.Parse(value);
  943.                     break
  944.                 case InternalPrimitiveTypeE.MonthDay:
  945.                     var= SoapMonthDay.Parse(value);
  946.                     break
  947.                 case InternalPrimitiveTypeE.Day:
  948.                     var= SoapDay.Parse(value);
  949.                     break
  950.                 case InternalPrimitiveTypeE.Month:
  951.                     var= SoapMonth.Parse(value);
  952.                     break
  953.                 case InternalPrimitiveTypeE.HexBinary:
  954.                     var= SoapHexBinary.Parse(value);
  955.                     break
  956.                 case InternalPrimitiveTypeE.Base64Binary:
  957.                     var= SoapBase64Binary.Parse(value);
  958.                     break
  959.                 case InternalPrimitiveTypeE.Integer:
  960.                     var= SoapInteger.Parse(value);
  961.                     break
  962.                 case InternalPrimitiveTypeE.PositiveInteger:
  963.                     var= SoapPositiveInteger.Parse(value);
  964.                     break
  965.                 case InternalPrimitiveTypeE. NonPositiveInteger:
  966.                     var= SoapNonPositiveInteger.Parse(value);
  967.                     break
  968.                 case InternalPrimitiveTypeE.NonNegativeInteger:
  969.                     var= SoapNonNegativeInteger.Parse(value);
  970.                     break
  971.                 case InternalPrimitiveTypeE.NegativeInteger:
  972.                     var= SoapNegativeInteger.Parse(value);
  973.                     break
  974.                 case InternalPrimitiveTypeE.AnyUri:
  975.                     var= SoapAnyUri.Parse(value);
  976.                     break
  977.                 case InternalPrimitiveTypeE.QName:
  978.                     var= SoapQName.Parse(value);
  979.                     break
  980.                 case InternalPrimitiveTypeE.Notation:
  981.                     var= SoapNotation.Parse(value);
  982.                     break
  983.                 case InternalPrimitiveTypeE.NormalizedString:
  984.                     var= SoapNormalizedString.Parse(value);
  985.                     break
  986.                 case InternalPrimitiveTypeE.Token:
  987.                     var= SoapToken.Parse(value);
  988.                     break
  989.                 case InternalPrimitiveTypeE.Language:
  990.                     var= SoapLanguage.Parse(value);
  991.                     break
  992.                 case InternalPrimitiveTypeE.Name:
  993.                     var= SoapName.Parse(value);
  994.                     break
  995.                 case InternalPrimitiveTypeE.Idrefs:
  996.                     var= SoapIdrefs.Parse(value);
  997.                     break
  998.                 case InternalPrimitiveTypeE.Entities:
  999.                     var= SoapEntities.Parse(value);
  1000.                     break
  1001.                 case InternalPrimitiveTypeE.Nmtoken:
  1002.                     var= SoapNmtoken.Parse(value);
  1003.                     break
  1004.                 case InternalPrimitiveTypeE.Nmtokens:
  1005.                     var= SoapNmtokens.Parse(value);
  1006.                     break
  1007.                 case InternalPrimitiveTypeE.NcName:
  1008.                     var= SoapNcName.Parse(value);
  1009.                     break
  1010.                 case InternalPrimitiveTypeE.Id:
  1011.                     var= SoapId.Parse(value);
  1012.                     break
  1013.                 case InternalPrimitiveTypeE.Idref:
  1014.                     var= SoapIdref.Parse(value);
  1015.                     break
  1016.                 case InternalPrimitiveTypeE.Entity:
  1017.                     var= SoapEntity.Parse(value);
  1018.                     break
  1019.                 default:
  1020.                     // InternalPrimitiveTypeE needs to be a primitive type
  1021.                     InternalST.SoapAssert((code != InternalPrimitiveTypeE.Invalid), "[Converter.FromString]!InternalPrimitiveTypeE.Invalid ");
  1022.                     if (code != InternalPrimitiveTypeE.Invalid)
  1023.                         var = Convert.ChangeType(value, ToTypeCode(code), CultureInfo.InvariantCulture);
  1024.                     else
  1025.                         var = value;
  1026.                     break;
  1027.             }
  1028.             InternalST.Soap( "Converter""FromString Exit "+((var == null)?"null":var+" var type "+((var==null)?"<null>":var.GetType().ToString())));
  1029.             return var;
  1030.         }
  1031.         internal static Type typeofISerializable = typeof(ISerializable);
  1032.         internal static Type typeofString = typeof(String);
  1033.         internal static Type typeofConverter = typeof(Converter);
  1034.         internal static Type typeofBoolean = typeof(Boolean);
  1035.         internal static Type typeofByte = typeof(Byte);
  1036.         internal static Type typeofChar = typeof(Char);
  1037.         internal static Type typeofDecimal = typeof(Decimal);
  1038.         internal static Type typeofDouble = typeof(Double);
  1039.         internal static Type typeofInt16 = typeof(Int16);
  1040.         internal static Type typeofInt32 = typeof(Int32);
  1041.         internal static Type typeofInt64 = typeof(Int64);
  1042.         internal static Type typeofSByte = typeof(SByte);
  1043.         internal static Type typeofSingle = typeof(Single);
  1044.         internal static Type typeofTimeSpan = typeof(TimeSpan);
  1045.         internal static Type typeofDateTime = typeof(DateTime);
  1046.         internal static Type typeofUInt16 = typeof(UInt16);
  1047.         internal static Type typeofUInt32 = typeof(UInt32);
  1048.         internal static Type typeofUInt64 = typeof(UInt64);
  1049.         internal static Type typeofSoapTime = typeof(SoapTime);
  1050.         internal static Type typeofSoapDate = typeof(SoapDate);
  1051.         internal static Type typeofSoapYear = typeof(SoapYear);
  1052.         internal static Type typeofSoapMonthDay = typeof(SoapMonthDay);
  1053.         internal static Type typeofSoapYearMonth = typeof(SoapYearMonth);
  1054.         internal static Type typeofSoapDay = typeof(SoapDay);
  1055.         internal static Type typeofSoapMonth = typeof(SoapMonth);
  1056.         internal static Type typeofSoapHexBinary = typeof(SoapHexBinary);
  1057.         internal static Type typeofSoapBase64Binary = typeof(SoapBase64Binary);
  1058.         internal static Type typeofSoapInteger = typeof(SoapInteger);
  1059.         internal static Type typeofSoapPositiveInteger = typeof(SoapPositiveInteger);
  1060.         internal static Type typeofSoapNonPositiveInteger = typeof(SoapNonPositiveInteger);
  1061.         internal static Type typeofSoapNonNegativeInteger = typeof(SoapNonNegativeInteger);
  1062.         internal static Type typeofSoapNegativeInteger = typeof(SoapNegativeInteger);
  1063.         internal static Type typeofSoapAnyUri = typeof(SoapAnyUri);
  1064.         internal static Type typeofSoapQName = typeof(SoapQName);
  1065.         internal static Type typeofSoapNotation = typeof(SoapNotation);
  1066.         internal static Type typeofSoapNormalizedString = typeof(SoapNormalizedString);
  1067.         internal static Type typeofSoapToken = typeof(SoapToken);
  1068.         internal static Type typeofSoapLanguage = typeof(SoapLanguage);
  1069.         internal static Type typeofSoapName = typeof(SoapName);
  1070.         internal static Type typeofSoapIdrefs = typeof(SoapIdrefs);
  1071.         internal static Type typeofSoapEntities = typeof(SoapEntities);
  1072.         internal static Type typeofSoapNmtoken = typeof(SoapNmtoken);
  1073.         internal static Type typeofSoapNmtokens = typeof(SoapNmtokens);
  1074.         internal static Type typeofSoapNcName = typeof(SoapNcName);
  1075.         internal static Type typeofSoapId = typeof(SoapId);
  1076.         internal static Type typeofSoapIdref = typeof(SoapIdref);
  1077.         internal static Type typeofSoapEntity = typeof(SoapEntity);
  1078.         internal static Type typeofISoapXsd = typeof(ISoapXsd);
  1079.         internal static Type typeofObject = typeof(Object);
  1080.         internal static Type typeofSoapFault = typeof(SoapFault);               
  1081.         internal static Type typeofTypeArray = typeof(System.Type[]);
  1082.         internal static Type typeofIConstructionCallMessage = typeof(System.Runtime.Remoting.Activation.IConstructionCallMessage);
  1083.         internal static Type typeofIMethodCallMessage = typeof(System.Runtime.Remoting.Messaging.IMethodCallMessage);
  1084.         internal static Type typeofReturnMessage = typeof(System.Runtime.Remoting.Messaging.ReturnMessage);
  1085.         internal static Type typeofSystemVoid = typeof(void);
  1086.         internal static Type typeofInternalSoapMessage = typeof(InternalSoapMessage);       
  1087.         internal static Type typeofHeader = typeof(System.Runtime.Remoting.Messaging.Header);       
  1088.         internal static Type typeofMarshalByRefObject = typeof(System.MarshalByRefObject);       
  1089.         internal static Assembly urtAssembly = Assembly.GetAssembly(typeofString);
  1090.         internal static String urtAssemblyString = urtAssembly.FullName;
  1091.     }
  1092. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值