Pārlūkot izejas kodu

2009-05-14 Atsushi Enomoto <[email protected]>

	* SerializationMap.cs: interface collection failed to serialize as
	  it was calling inappropriate GetInterfaceMap().

	* XmlObjectSerializerTest.cs : added serialization test for
	  interface collection.


svn path=/trunk/mcs/; revision=134100
Atsushi Eno 16 gadi atpakaļ
vecāks
revīzija
d691a2d3df

+ 5 - 0
mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/ChangeLog

@@ -1,3 +1,8 @@
+2009-05-14  Atsushi Enomoto  <[email protected]>
+
+	* SerializationMap.cs: interface collection failed to serialize as
+	  it was calling inappropriate GetInterfaceMap().
+
 2009-04-01  Atsushi Enomoto  <[email protected]>
 
 	* XmlFormatterDeserializer.cs : more hack to handle empty

+ 12 - 8
mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs

@@ -566,14 +566,18 @@ namespace System.Runtime.Serialization
 			var icoll = RuntimeType.GetInterfaces ().FirstOrDefault (
 				iface => iface.IsGenericType && iface.GetGenericTypeDefinition () == typeof (ICollection<>));
 			if (icoll != null) {
-				var imap = RuntimeType.GetInterfaceMap (icoll);
-				for (int i = 0; i < imap.InterfaceMethods.Length; i++)
-					if (imap.InterfaceMethods [i].Name == "Add") {
-						add_method = imap.TargetMethods [i];
-						break;
-					}
-				if (add_method == null)
-					add_method = type.GetMethod ("Add", icoll.GetGenericArguments());
+				if (RuntimeType.IsInterface) {
+					add_method = RuntimeType.GetMethod ("Add", icoll.GetGenericArguments ());
+				} else {
+					var imap = RuntimeType.GetInterfaceMap (icoll);
+					for (int i = 0; i < imap.InterfaceMethods.Length; i++)
+						if (imap.InterfaceMethods [i].Name == "Add") {
+							add_method = imap.TargetMethods [i];
+							break;
+						}
+					if (add_method == null)
+						add_method = type.GetMethod ("Add", icoll.GetGenericArguments ());
+				}
 			}
 		}
 

+ 5 - 0
mcs/class/System.Runtime.Serialization/Test/System.Runtime.Serialization/ChangeLog

@@ -1,3 +1,8 @@
+2009-05-14  Atsushi Enomoto  <[email protected]>
+
+	* XmlObjectSerializerTest.cs : added serialization test for
+	  interface collection.
+
 2009-03-12  Atsushi Enomoto  <[email protected]>
 
 	* XmlObjectSerializerTest.cs : added test for dictionary with

+ 15 - 0
mcs/class/System.Runtime.Serialization/Test/System.Runtime.Serialization/XmlObjectSerializerTest.cs

@@ -1181,6 +1181,15 @@ namespace MonoTests.System.Runtime.Serialization
 			Assert.AreEqual ("bar", d ["foo"], "#3");
 		}
 
+		[Test]
+		[Category ("NotWorking")] // FIXME: remove once #503728 gets fixed.
+		public void SerializeInterfaceCollection ()
+		{
+			var ser = new DataContractSerializer (typeof (InterfaceCollectionType));
+			using (var xw = XmlWriter.Create (TextWriter.Null))
+				ser.WriteObject (xw, new InterfaceCollectionType ());
+		}
+
 		private T Deserialize<T> (string xml)
 		{
 			return Deserialize<T> (xml, typeof (T));
@@ -1450,6 +1459,12 @@ namespace MonoTests.System.Runtime.Serialization
 		public string this [int index] { get { return l [index]; } set { l [index] = value; } }
 	}
 
+	[DataContract]
+	internal class InterfaceCollectionType
+	{
+		[DataMember]
+		public IList<int> Array { get; set; }
+	}
 }
 
 [DataContract]