How do I serialize a child class?
how do I include the serialized data from a child class where both impliment iserializeable?
Class A
Implements ISerializable
dim _B as new B
Class B
开发者_如何转开发 Implements ISerializable
dim _C as integer
end class
end class
I need to be able to serialize object B's data along with the data that is being serialized via the GetObjectData method for class A. In my use case Class A also happens to be a derived class.
Only implement ISerializable when you want to customize (or extend) the data that is being serialized. Use the System.SerializableAttribute code attribute instead on both classes and it should work.
MSDN is your friend: http://msdn.microsoft.com/en-us/library/4abbf6k0(VS.80).aspx
If you mean when you serialize type A
, any objects of type B
are also serialized then it is not possible.
For this you need to have a mechanism that tracks objects of type B
created and also some way to keep relationship between object of type A
and type B
.
If A
or B
are used independently of each other then I don't see any need for this.
精彩评论