Serialisation - whats coming over?

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Using serialisation can anyone tell me how i can use it to work out what
object was serialised?

For example i have a class Ball and another class Bat.

i serialise the first class Ball and send it over the wire via sockets.

The receiving end receives the data and deserialises. But how do i know
after deserialising it to an object whether the Ball object was sent across
or the Bat object was sent across?

c# code please
 
Hello, Daniel!

D> For example i have a class Ball and another class Bat.

D> i serialise the first class Ball and send it over the wire via sockets.

D> The receiving end receives the data and deserialises. But how do i know
D> after deserialising it to an object whether the Ball object was sent
D> across or the Bat object was sent across?

Did you try to call object.GetType() method on deserialized object?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Thought it would be to do with that but how do i use it?

object myObject = bf.Deserialise();

myObject.GetType(); ?how do i do this bit?
 
Hello, Daniel!

D> object myObject = bf.Deserialise();

D> myObject.GetType(); ?how do i do this bit?

If I understood you correctly...

the pseudo code will be like this
objType = deserializedObj.GetType();

switch objType
case Type1
DoStuffWithType1
case Type2
DoStuffWithType2
etc


--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Daniel said:
Using serialisation can anyone tell me how i can use it to work out what
object was serialised?

For example i have a class Ball and another class Bat.

i serialise the first class Ball and send it over the wire via sockets.

The receiving end receives the data and deserialises. But how do i know
after deserialising it to an object whether the Ball object was sent across
or the Bat object was sent across?

object obj = bf.Deserialize(...);

if (obj is Bat) {
// obj is a Bat
} else if (obj is Ball) {
// obj is a Ball
}

does that help?

Max
 
Turns out i cant do a swtich on an objecttype.

So i had to change the type to string then do the switch against that. Works
now, thanks for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top