On my code i hold some collection of ISerialize.
Dictionary<int, ISerialize> // the int is the key and its mean the ID
And i have 2 type of object =>
public interface ISerialize
{
byte[] Serialize();
ISerialize DeSerialize();
}
class Elem1 : ISerialize
{
public long ID { get; set; }
public string Name { get; set; }
public byte[] Serialize()
{
// Serialize implement
}
public ISerialize DeSerialize()
{
// DeSerialize implement
}
}
class Elem2 : ISerialize
{
public long ID { get; set; }
public string Name1 { get; set; }
public string Name2 { get; set; }
public int Age { get; set; }
public byte[] Serialize()
{
// Serialize implement
}
public ISerialize DeSerialize()
{
// DeSerialize implement
}
}
I want to Serialize and DeSerialize all the Dictionary.
So i know how to do the Serialize ( just go with foreach and create continues byte[] )
But when i doing the DeSerialize i can't know what kind of type i dealing with ( Elem1 or Elem2 ) and i can't actually to do the DeSerialize.
How to solve this ? What i the best practice on this ?