Now Hierarchy is that there is a class named "Student"
There are two child classes "GraduateStudent" and "HighSchoolStudent".
I worte the following code for serializing the student and
deserializing.
Now the problem is that as i do not know the type of Student while
deserializing so i get an error on line
student= (Student)deserializer.Deserialize(memoryStream);
Any help will be highly appriciated
public void SerializeMyStudent(Student student)
{
NetworkStream netWorkStream=null;
try
{
XmlSerializer serializer=new XmlSerializer(student.GetType());
netWorkStream=new NetworkStream(_clientSocket);
Stream stream=(Stream)netWorkStream;
serializer.Serialize(stream,student);
}
finally
{
netWorkStream.Close();
}
}
and the deserializeMessage is like
public bool DeserializeMessage(ref NetworkStream networkStream)
{
XmlSerializer deserializer=null;
int count=0;
Byte []buffer=new Byte[BUFFER_SIZE];
count=networkStream.Read(buffer,0,buffer.Length);
if(count <= 0)
{
message=null;
return false;
}
Student student= new Student();
deserializer=new XmlSerializer(student.GetType());
MemoryStream memoryStream=null;
memoryStream=new MemoryStream(buffer,0,count);
student= (Student)deserializer.Deserialize(memoryStream);
return true;
}