Hi all,
I know this topic has been asked quite a bit. However, I cannot seem to
find a solution for my particular problem.
I have a class that contains properties of strongly typed ICollection
objects. For example,
class MyClass
{
public MyTypedCollectionA A
{
get { return _collA; }
set { _collA = value; }
}
public MyTypedCollectionB B
{
get { return _collB; }
set { _collB = value; }
}
private MyTypedCollectionA _collA;
private MyTypedCollectionB _collB;
}
When I serialize this class to XML, it behaves as I would like - only
the non null collection objects are serialized. So if A is not null and
B is null, the resulting XML is
<MyClass>
<A>
.....
</A>
</MyClass>
However, when I try to deserialize the above XML, BOTH collections are
created. A gets populated as expected, but B contains an empty array.
Since B was not included in the XML, I would like the
MyTypedCollectionB object set to null.
How do I accomplish this? There are cases where I need to handle empty
arrays so returning null if the collection is empty is not an option.
There has to be another way. Please help!
Thanks