I know that you can't serialize/deserialize using an interface but I'm confused by behaviour I'm seeing.
When I deserialize and cast back to the interface, some properties are null. But if I cast back to the concrete type the same property has a value?
So, given this XML (shortened for brevity):
<Page>
<ComponentPresentations>
<ComponentPresentation>
<Component>
<Categories>
<Category>
<Id>tcm:35-540-512</Id>
Deserializing with
var serializer = new XmlSerializer(typeof(Page));
page = (IPage)serializer.Deserialize(reader);
page.ComponentPresentations[0].Component.Categories <-- is null
But if I cast back to the type,
var serializer = new XmlSerializer(typeof(Page));
page = (Page)serializer.Deserialize(reader);
page.ComponentPresentations[0].Component.Categories <-- is not null!
The Page type exposes the interface Categories property and a non-interface property - I assume to get around the serializing interface problem.
public List<Category> Categories { get; set; }
[XmlIgnore]
IList<ICategory> IComponent.Categories
{
get { return Categories as IList<ICategory>; }
}
Is this because the interface property doesn't expose a setter?