diff options
author | Lluis Sanchez <lluis@novell.com> | 2005-12-01 15:21:08 +0300 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2005-12-01 15:21:08 +0300 |
commit | 1e8f13ce21920681bd2c5aebb3b84843c7935098 (patch) | |
tree | 95210b000b2573b5f952f5aef24eae2d4f47cce4 /mcs/class/System.XML | |
parent | 4c8c94dda7ce758e2bec04ec760db72f777537a6 (diff) |
2005-12-01 Lluis Sanchez Gual <lluis@novell.com>
* TypeTranslator.cs: In GetTypeData, if an xmlType is specified for
a cli array type, consider it refering to the type of array elements.
This fixes bug #76860. Also added some locking.
svn path=/trunk/mcs/; revision=53760
Diffstat (limited to 'mcs/class/System.XML')
-rw-r--r-- | mcs/class/System.XML/System.Xml.Serialization/ChangeLog | 6 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs | 52 |
2 files changed, 44 insertions, 14 deletions
diff --git a/mcs/class/System.XML/System.Xml.Serialization/ChangeLog b/mcs/class/System.XML/System.Xml.Serialization/ChangeLog index 4d05eeded7e..3390dca36f3 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/ChangeLog +++ b/mcs/class/System.XML/System.Xml.Serialization/ChangeLog @@ -1,3 +1,9 @@ +2005-12-01 Lluis Sanchez Gual <lluis@novell.com> + + * TypeTranslator.cs: In GetTypeData, if an xmlType is specified for + a cli array type, consider it refering to the type of array elements. + This fixes bug #76860. Also added some locking. + 2005-11-27 Konstantin Triger <kostat@mainsoft.com> * TypeData.cs, XmlSchemaExporter.cs, TypeTranslator.cs: correctly diff --git a/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs b/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs index 28eb6df975f..dbb7b72c467 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs +++ b/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs @@ -42,10 +42,12 @@ namespace System.Xml.Serialization { static Hashtable nameCache; static Hashtable primitiveTypes; + static Hashtable primitiveArrayTypes; static TypeTranslator () { nameCache = new Hashtable (); + primitiveArrayTypes = new Hashtable (); // XSD Types with direct map to CLR types @@ -119,22 +121,44 @@ namespace System.Xml.Serialization public static TypeData GetTypeData (Type type, string xmlDataType) { - if ((xmlDataType != null) && (xmlDataType.Length != 0)) return GetPrimitiveTypeData (xmlDataType); - - TypeData typeData = nameCache[type] as TypeData; - if (typeData != null) return typeData; - - string name; - if (type.IsArray) { - string sufix = GetTypeData (type.GetElementType ()).XmlType; - name = GetArrayName (sufix); + if ((xmlDataType != null) && (xmlDataType.Length != 0)) { + // If the type is an array, xmlDataType specifies the type for the array elements, + // not for the whole array. The exception is base64Binary, since it is a byte[], + // that's why the following check is needed. + TypeData at = GetPrimitiveTypeData (xmlDataType); + if (type.IsArray && type != at.Type) { + lock (primitiveArrayTypes) { + TypeData tt = (TypeData) primitiveArrayTypes [xmlDataType]; + if (tt != null) + return tt; + if (at.Type == type.GetElementType ()) { + tt = new TypeData (type, GetArrayName (at.XmlType), false); + primitiveArrayTypes [xmlDataType] = tt; + return tt; + } + else + throw new InvalidOperationException ("Cannot convert values of type '" + type.GetElementType () + "' to '" + xmlDataType + "'"); + } + } + return at; } - else - name = XmlConvert.EncodeLocalName (type.Name); - typeData = new TypeData (type, name, false); - nameCache[type] = typeData; - return typeData; + lock (nameCache) { + TypeData typeData = nameCache[type] as TypeData; + if (typeData != null) return typeData; + + string name; + if (type.IsArray) { + string sufix = GetTypeData (type.GetElementType ()).XmlType; + name = GetArrayName (sufix); + } + else + name = XmlConvert.EncodeLocalName (type.Name); + + typeData = new TypeData (type, name, false); + nameCache[type] = typeData; + return typeData; + } } public static bool IsPrimitive (Type type) |