Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason_naylor <jason_naylor@sil.org>2015-03-04 18:58:01 +0300
committerjason_naylor <jason_naylor@sil.org>2015-03-04 19:25:37 +0300
commit60ef531176c7d293a89ea64cf3c81b4fc92d7da4 (patch)
tree8aedc18e2b5aa3bef365950a9e9c9a6e7709c011
parent6b74a2814f545ae0aafca633a9933bbe4c9b1f57 (diff)
Fix for the XMLSerializer bug 18558
* Find the type map element that is the most-specific to the object in question, not the first type it is an instance of Change-Id: I1867e790bf9f377ce0ae02871f4561b760e27624
-rw-r--r--mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberElement.cs20
-rw-r--r--mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs8
2 files changed, 21 insertions, 7 deletions
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberElement.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberElement.cs
index f05ab6b2a01..072f9fee05c 100644
--- a/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberElement.cs
+++ b/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberElement.cs
@@ -83,9 +83,23 @@ namespace System.Xml.Serialization
else
{
if (memberValue == null)
- return (XmlTypeMapElementInfo) _elementInfo[0];
- foreach (XmlTypeMapElementInfo elem in _elementInfo)
- if (elem.TypeData.Type.IsInstanceOfType (memberValue)) return elem;
+ return (XmlTypeMapElementInfo) _elementInfo [0];
+ else
+ {
+ XmlTypeMapElementInfo bestTypeElem = null;
+ // Select the most-specific type for the given memberValue
+ foreach (XmlTypeMapElementInfo elem in _elementInfo)
+ {
+ if (elem.TypeData.Type.IsInstanceOfType (memberValue))
+ {
+ if (bestTypeElem == null || elem.TypeData.Type.IsSubclassOf (bestTypeElem.TypeData.Type))
+ {
+ bestTypeElem = elem;
+ }
+ }
+ }
+ return bestTypeElem;
+ }
}
return null;
}
diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
index 19e7a9c21f4..1c81dd737f4 100644
--- a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
+++ b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
@@ -2864,21 +2864,21 @@ namespace MonoTests.System.XmlSerialization
#endregion //GenericsSeralizationTests
#region XmlInclude on abstract class tests (Bug #18558)
[Test]
- public void TestSerializeIntermediateType()
+ public void TestSerializeIntermediateType ()
{
string expectedXml = "<ContainerTypeForTest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><XmlIntermediateType intermediate=\"false\"/></ContainerTypeForTest>";
var obj = new ContainerTypeForTest();
- obj.MemberToUseInclude = new IntermediateTypeForTest();
+ obj.MemberToUseInclude = new IntermediateTypeForTest ();
Serialize (obj);
Assert.AreEqual (Infoset (expectedXml), WriterText, "Serialized Output : " + WriterText);
}
[Test]
- public void TestSerializeSecondType()
+ public void TestSerializeSecondType ()
{
string expectedXml = "<ContainerTypeForTest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><XmlSecondType intermediate=\"false\"/></ContainerTypeForTest>";
var obj = new ContainerTypeForTest();
- obj.MemberToUseInclude = new SecondDerivedTypeForTest();
+ obj.MemberToUseInclude = new SecondDerivedTypeForTest ();
Serialize (obj);
Assert.AreEqual (Infoset (expectedXml), WriterText, "Serialized Output : " + WriterText);
}