By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Array Serialization Help

P: n/a
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

Mar 22 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.