提交 2002994d 编写于 作者: M Marcos Henrich

Merge pull request #2419 from esdrubal/xmlsubclassel

[System.Xml] Fix sub class serialization on lists 
......@@ -646,8 +646,15 @@ namespace System.Xml.Serialization
{
if (memberValue == null) return null;
Type type = memberValue.GetType();
foreach (XmlTypeMapElementInfo elem in _itemInfo)
if (elem.TypeData.Type == type) return elem;
XmlTypeMapElementInfo bestMatch = null;
foreach (XmlTypeMapElementInfo elem in _itemInfo) {
if (elem.TypeData.Type == type)
return elem;
if (elem.TypeData.Type.IsAssignableFrom (type) &&
(bestMatch == null || elem.TypeData.Type.IsAssignableFrom (bestMatch.TypeData.Type)))
bestMatch = elem;
}
return bestMatch;
}
return null;
}
......
......@@ -711,6 +711,13 @@ namespace MonoTests.System.Xml.TestClasses
public object data;
}
public class SubclassTestList
{
[XmlElement ("a", typeof (SimpleClass))]
[XmlElement ("b", typeof (SubclassTestBase))]
public List<object> Items;
}
public class DictionaryWithIndexer : DictionaryBase
{
public TimeSpan this[int index]
......
......@@ -1939,6 +1939,17 @@ namespace MonoTests.System.XmlSerialization
Assert.AreEqual (Infoset (res), WriterText);
}
[Test] // Covers #36829
public void TestSubclassElementList ()
{
var o = new SubclassTestList () { Items = new List<object> () { new SubclassTestSub () } };
Serialize (o);
string res = "<SubclassTestList xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
res += "<b xsi:type=\"SubclassTestSub\"/></SubclassTestList>";
Assert.AreEqual (Infoset (res), WriterText);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestArrayAttributeWithWrongDataType ()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册