I've got two (different) C# systems which communicate by XML. We have agreed on an XML format.
The next thing I want to do is serialize a class:
public class Parent
{
public IChild Child { get; set; }
public string Name { get; set; }
}
public interface IChild
{
string Name { get; set; }
}
public class Girl:IChild
{
public string Name { get; set; }
public string FavDoll { get; set; }
}
public class Boy : IChild
{
public string Name { get; set; }
public string FavCar { get; set; }
}
Result when using IXmlSerializer:
When using IXmlSerializable I get a exception there is no constructor on the Interface IChild (wellwaddayaknow).
Ok, fixed that (thanks @Giedrius)
And less ns thanks to @RobertH
<Parent>
<Child>
<Boy>
<Name>Bill</Name>
<FavCar>Chevvy</FavCar>
</Boy>
</Child>
</Parent>
When using DataContract I get a xmlns has a reference to the namespace. Which isn't present on the other system. So when deserializing I get a exception the reference isn't there.
<Parent xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Child xmlns:d2p1="TestConsole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" i:type="d2p1:TestConsole.Boy">
<FavCar xmlns="http://schemas.datacontract.org/2004/07/TestConsole">Chevvy</FavCar>
<Name xmlns="http://schemas.datacontract.org/2004/07/TestConsole">Bill</Name>
</Child>
</Parent>
Is my only option to use XDocument and generate a lot of loc's?