There is an interesting article -
http://www.devhood.com/tutorials/tut...=542&printer=t
It shows how to serialize the ArrayList of identical objects. I did it a
year ago and it works fine. The question is if the ArrayList has a set of
different objects of different type, every time different. We know what
types should be involved, but we don't know what objects in what order and
how many are used in the ArrayList. What I really want - to write a
universal class-wrapper for ArrayList to let me serialize and deserialize my
ArrayList with the objects of different types.
What I'm thinking now is:
1) to make all objects involved into the process serializable;
2) serialize all objects in ArrayList one by one, storing their ObjectType
(class name?);
3) create a set of strings containing serialized XML data from all objects;
4) finally serialize and write this serialized set of strings in file, on
the database or wherever.
The back way is almost the same:
1) deserialize this intermediate object (array of strings);
2) create our ArrayList and deserialize all objects one by one using (1);
.... enjoy.
Disadvantages are:
1) speed - it obviously should be slowly;
2) intermediate object and memory consumption;
Advantages are:
1) flexibility - we can use any objects in any combination to create our
ArrayList of objects;
2) flexibility - we can create new objects and add them expanding the
application in future without any risk;
3) flexibility - if we use a standard - built-in deserialization we can skip
any fields if they are not included into serialized string, it can be done
automatically, the values will be used as default;
Any idea else? Is it possible to make it simpler and shorter? Yes, I saw
articles like:
---------------------------------------------------------------------------------------------------
http://www.codeproject.com/csharp/objserial.asp
//Deserialization constructor.
public Employee(Serial izationInfo info, StreamingContex t ctxt)
{
//Get the values from info and assign them to the appropriate properties
EmpId = (int)info.GetVa lue("EmployeeId ", typeof(int));
EmpName = (String)info.Ge tValue("Employe eName", typeof(string)) ;
}
//Serialization function.
public void GetObjectData(S erializationInf o info, StreamingContex t ctxt)
{
//You can use any custom name for your name-value pair. But make sure
you
// read the values with the same name. For ex:- If you write EmpId as
"EmployeeId "
// then you should read the same with "EmployeeId "
info.AddValue(" EmployeeId", EmpId);
info.AddValue(" EmployeeName", EmpName);
}
---------------------------------------------------------------------------------------------------
but all these articles are offering to work with only object type and that
doesn't work for my case at all. That's cool to have a data loader from XML
string in the class constructor, but actually it doesn't help me to
understand what class should be used to deserialize the whole collection
object by object.
Maybe I'm loosing something?
Just D.