I am trying to deserialize some XML files into some classes that have been simplified to the following:
[XmlRoot("person")]
[Serializable]
public class Person
{
[XmlElement]
public Toy Toy { get; set; }
}
[Serializable]
public class ActionMan : Toy
{
[XmlElement("guns")]
public string Guns;
}
[Serializable]
public class Doll : Toy
{
[XmlElement("name")]
public String Name;
}
[XmlInclude(typeof(Doll))]
[XmlInclude(typeof(ActionMan))]
public class Toy
{
}
[TestFixture]
public class ToyTest
{
[Test]
public void testHierarchy()
{
String filePath = @"test\brother.xml";
String sisfilePath = @"test\sister.xml";
var serializer = new XmlSerializer(typeof(Person));
Person brother = (Person)serializer.Deserialize(new FileStream(filePath, FileMode.Open));
Person sister = (Person)serializer.Deserialize(new FileStream(sisfilePath, FileMode.Open));
Assert.IsNotNull(brother);
Assert.IsNotNull(sister);
Assert.IsAssignableFrom(typeof(ActionMan),brother.Toy);
Assert.IsAssignableFrom(typeof(Doll),sister.Toy);
}
}
I want to use C # serialization (I know that I can use my deserializer), and I think that maybe there is just a certain tag that I don’t know about (and I'm sure I have extra tags).
here is one of the xml files:
<person>
<doll>
<name>Jill</name>
</doll>
</person>
The error I get is "Expected: Assigned from" on the third statement
source
share