Sfoglia il codice sorgente

* XmlReflectionImporter.cs: type namespace must never be used as root
namespace. This fixes bug #52772.

svn path=/trunk/mcs/; revision=22016

Lluis Sanchez 22 anni fa
parent
commit
cc725012f1

+ 5 - 0
mcs/class/System.XML/System.Xml.Serialization/ChangeLog

@@ -1,3 +1,8 @@
+2004-01-13  Lluis Sanchez Gual  <[email protected]>
+
+	* XmlReflectionImporter.cs: type namespace must never be used as root
+	  namespace. This fixes bug #52772.
+
 2004-01-08  Nick Drochak <[email protected]>
 
 	* XmlSchemaImporter.cs: Removed unused variable.

+ 9 - 8
mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs

@@ -138,7 +138,7 @@ namespace System.Xml.Serialization {
 
 		XmlTypeMapping CreateTypeMapping (TypeData typeData, XmlRootAttribute root, string defaultXmlType, string defaultNamespace)
 		{
-			string membersNamespace;
+			string rootNamespace = "";
 			string elementName;
 			bool includeInSchema = true;
 			XmlAttributes atts = null;
@@ -170,7 +170,6 @@ namespace System.Xml.Serialization {
 				includeInSchema = atts.XmlType.IncludeInSchema;
 			}
 
-			membersNamespace = defaultNamespace;
 			elementName = defaultXmlType;
 
 			if (root != null)
@@ -178,11 +177,13 @@ namespace System.Xml.Serialization {
 				if (root.ElementName != null && root.ElementName != String.Empty)
 					elementName = root.ElementName;
 				if (root.Namespace != null && root.Namespace != String.Empty)
-					membersNamespace = root.Namespace;
+					rootNamespace = root.Namespace;
 			}
 
-			if (membersNamespace == null) membersNamespace = "";
-			XmlTypeMapping map = new XmlTypeMapping (elementName, membersNamespace, typeData, defaultXmlType, defaultNamespace);
+			if (rootNamespace == null) rootNamespace = "";
+			if (defaultNamespace == null || defaultNamespace.Length == 0) defaultNamespace = rootNamespace;
+			
+			XmlTypeMapping map = new XmlTypeMapping (elementName, rootNamespace, typeData, defaultXmlType, defaultNamespace);
 			map.IncludeInSchema = includeInSchema;
 			relatedMaps.Add (map);
 			
@@ -213,7 +214,7 @@ namespace System.Xml.Serialization {
 				foreach (XmlReflectionMember rmember in members)
 				{
 					if (rmember.XmlAttributes.XmlIgnore) continue;
-					classMap.AddMember (CreateMapMember (rmember, map.Namespace));
+					classMap.AddMember (CreateMapMember (rmember, map.XmlTypeNamespace));
 				}
 //			}
 //			catch (Exception ex) {
@@ -331,7 +332,7 @@ namespace System.Xml.Serialization {
 				else if (elem.TypeData.IsComplexType)
 					elem.MappedType = ImportTypeMapping (itemType, null, defaultNamespace);
 
-				if (elem.MappedType != null) elem.ElementName = elem.MappedType.ElementName;
+				if (elem.MappedType != null) elem.ElementName = elem.MappedType.XmlType;
 				else elem.ElementName = TypeTranslator.GetTypeData(itemType).XmlType ;
 
 				elem.Namespace = (defaultNamespace != null) ? defaultNamespace : "";
@@ -350,7 +351,7 @@ namespace System.Xml.Serialization {
 			else
 			{
 				XmlTypeMapElementInfo elem = ((XmlTypeMapElementInfo)list[0]);
-				if (elem.MappedType != null) baseName = TypeTranslator.GetArrayName (elem.MappedType.ElementName);
+				if (elem.MappedType != null) baseName = TypeTranslator.GetArrayName (elem.MappedType.XmlType);
 				else baseName = TypeTranslator.GetArrayName (elem.ElementName);
 			}