Forráskód Böngészése

* TypeData.cs: Type of item of ICollections is now taken from the Item(int) property. Add() can
be overlodaded, so it is not good for this.
* XmlSerializationWriterInterpreter.cs: Fix ambiguity bug when getting Item property of a collection.

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

Lluis Sanchez 22 éve
szülő
commit
da1a2d5e1f

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

@@ -1,3 +1,9 @@
+2003-06-28  Lluis Sanchez Gual <[email protected]>
+
+	* TypeData.cs: Type of item of ICollections is now taken from the Item(int) property. Add() can
+	  be overlodaded, so it is not good for this.
+	* XmlSerializationWriterInterpreter.cs: Fix ambiguity bug when getting Item property of a collection.
+
 2003-06-24  Lluis Sanchez Gual <[email protected]>
 
 	* XmlTypeMapElementInfo.cs: no need to compare nesting level in Equals.

+ 12 - 1
mcs/class/System.XML/System.Xml.Serialization/TypeData.cs

@@ -10,6 +10,7 @@
 
 using System;
 using System.Collections;
+using System.Reflection;
 
 namespace System.Xml.Serialization
 {
@@ -18,6 +19,7 @@ namespace System.Xml.Serialization
 		Type type;
 		string elementName;
 		SchemaTypes sType;
+		Type listItemType;
 
 		public TypeData (Type type, string elementName, bool isPrimitive)
 		{
@@ -96,12 +98,21 @@ namespace System.Xml.Serialization
 		{
 			get
 			{
+				if (listItemType != null) return listItemType;
+
 				if (SchemaType != SchemaTypes.Array)
 					throw new InvalidOperationException (Type.FullName + " is not a collection");
 				else if (type.IsArray) 
-					return type.GetElementType ();
+					listItemType = type.GetElementType ();
+				else if (type.GetInterface ("ICollection") != null)
+				{
+					PropertyInfo prop = type.GetProperty ("Item", new Type[] { typeof (int) });
+					return prop.PropertyType;
+				}
 				else
 					return type.GetMethod ("Add").GetParameters()[0].ParameterType;
+
+				return listItemType;
 			}
 		}
 	}

+ 2 - 2
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs

@@ -225,7 +225,7 @@ namespace System.Xml.Serialization
 			}
 			else if (member.DefaultValue != null) {
 				object val = GetMemberValue (member, ob, isValueList);
-				if (val != null && val.Equals (member.DefaultValue)) return false;
+				if (val != null && member.DefaultValue != null && val.Equals (member.DefaultValue)) return false;
 			}
 			return true;
 		}
@@ -340,7 +340,7 @@ namespace System.Xml.Serialization
 			else if (ob is ICollection)
 			{
 				int count = (int) listType.Type.GetProperty ("Count").GetValue(ob,null);
-				PropertyInfo itemProp = listType.Type.GetProperty ("Item");
+				PropertyInfo itemProp = listType.Type.GetProperty ("Item", new Type[] { typeof(int) });
 				object[] index = new object[1];
 				for (int n=0; n<count; n++)
 				{