Really difficult situation to deal with it...

mariano_donati

Active member
Joined
Nov 30, 2005
Messages
41
Programming Experience
Beginner
Hi everyone, I'm greatly surprised with this forum, I'm from Argentina, and I member of different forums in spanish, but nothing like vbForums and vbdotnetforum. Well, I have to solve this trouble that I mention below.
I have this client/server application, they send and receive different serialized objects. When I received, for example, in my client application one of this objects, I need to convert it to the right type for using its properties.
Each object I send, inherits from a base class named EventSender. It has a MustOverrides property that returns the class of the object, let's say Message or Image or ClientConnection objects. So the structure that I follow is like this:

Dim ESender As EventSender = CType(DeserializeBytes(Bytes()), EventSender) 'DeserializeBytes() function returns a EventSender object after deserializing the bytes that I pass for param

Select Case ESender.GetObjectClass 'I use the MustOverrideProperty from the EventSenderObject to know wich object I'm receiving

Case Enum.ClientConnection 'Enum that defines different kinds of objects

Dim E As ClientConnection = CType(ESender, ClientConnection)

'Here I use the right properties of the object that I received

Case Enum.Message

Dim E As Message = CType(ESender, Message)

'Same thing...

End Select


--------------

Well, the thing is that I realized that I can't convert a object wich is the base object, into another wich inherits from it!. So, how can I do to know wich object is the application receiving?, and even more important, how can I do to user the correct properties of the object received?.

Thanks a lot for at least read my message.
Regards!.
 
i know this is an in-efficiant long shot (i dont have any clues) but you could have it try to CType every type of object that's allowed to be sent to it and the one on the list that doesnt return an error is what the object is

perhaps kulrom or jmcilhinney will know of a better solution
 
Hi JuggaloBrotha, I keep the same structure of the code, but modified a function that returned a EventSender object and converted it into a Overload function that return each valid type of my enum.
Thanks anyway.
Regards.
 
Back
Top