Click here to Skip to main content
14,695,085 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am writing a windows form application with C#.

There is one ArrayList which includes several objects. And I successfully wrote code to serialize this ArrayList to be an XML file, and can deserialize this XML to back to ArrayList.

However, the above process is based on the assumption that I know the length(number) of objects when doing serialization or deserialization.

The question and problem now is :
How can I know the length(number) of objects in an exited XML file (including serialized ArrayList) before I would first deserialize it ? Since the instruction below need a DataType to match the length of objects ?

Type[ ] DataType = new Type[ ? ]  // how can I know the lenght ?
XmlSerializer xs_load = new XmlSerializer(typeof(ArrayList), DataType);
Posted
Updated 4-Jun-10 3:44am
v2

1 solution

Like this

XmlSerializer xs_load = new XmlSerializer(typeof(ArrayList), new Type[] {typeof(YourType1), typeof(YourType2), etc..});


Cheers
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900