December 20th, 2005, 5:31 pm
Guys, can you please help me with the following issue.I want to serialize objects in C# with minimum effort. Let's say I have the following classes:class ABase // this is a base clase{ public int x_; public ABase() { x_ = 0; }}class AChild : ABase // this one is derived from ABase{ public int y_; public AChild() { y_ = 0; }}class BBase // another base class{ public int z_; public BBase() { z_ = 0; }}class BChild : BBase // derived from BBase{ public ABase obj_; public BChild(ABase obj) { obj_ = obj; }}Now let's say that I have the objectBBase t = new BChild(new AChild());I want to use BinaryFormatter.Serialize() and BinaryFormatter.Deserialize() methods to serialize object t into a stream and deserialize it afterwards.My question is whether serialization is deep or shallow, whether virtualism is preserved after serialization/deserialization of the object, and what I should do to make serialization working properly. More specifically, I am concerned if my application will understand that the deserialized object is actually of type BChild and not BBase and if it understands that, will it understand that obj_ variable of the deserialized object is of type AChild and not of ABase?Please help ASAP! Thanks a lot in advance!P.S. The variables x_, y_, z_ are just for classes to have something inside.
Last edited by
TheTiger on December 19th, 2005, 11:00 pm, edited 1 time in total.