extending serialization

A

Aaron Clamage

Hi,

I'm not sure that if this is the right forum, but any help would be greatly
appreciated.

I am porting some java serialization code to c# and I can't figure out the
correct way to do it. It seems that either I can use default serialization
or implement ISerializable. Is there any way to do both (e.g. extend the
default serialization). In other words, I want to be able to implement my
custom serialization code but call the default serialization code as well.
In java, I can do this:

private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
//implement my custom code
}

It seems there is no .NET equivalent. In particular I have a class that has
a GraphicsPath member. This class implements ISerializable so that it can
correctly serialize the path. But, for the other members including
references to other objects, I would like to use the default serialization.
Is this possible? Moreover this class derives from a serializable class
that does not implement ISerializable. Does the derived class have to
serialize all of the inherited members as well, if it chooses to do custom
serialization.

Thanks so much,
Aaron
 
A

Aaron Clamage

To add to/refine this question a bit, is it possible to mix and match custom
and default serialization along an inheritance hierarchy. If a base class
uses custom serialization can a derived class use default serialization or
vice-versa? I haven't been able to make either of these work.

If anyone can help here, please respond...

Aaron
 
J

Jay B. Harlow [MVP - Outlook]

Aaron,
If you don't have them the following articles covers every thing you wanted
to know about serialization but were afraid to ask:

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

One of the articles discusses how to leverage the FormatterServices class
with your own code. (read mix & match ISerializable classes with "default
serialization" classes) FormatterServices is the library that the "default
serialization" code uses to serialization a class that does not implement
ISerializable.

Hope this helps
Jay
 
M

Mike Schilling

Jay B. Harlow said:
Aaron,
If you don't have them the following articles covers every thing you wanted
to know about serialization but were afraid to ask:

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

They're good articles and I'm grateful to Mr. Richter for writing them, but
they don't take the place of a precise specification like Java's

http://java.sun.com/products/jdk/1.2/docs/guide/serialization/spec/serialTOC.doc.html

AFAIK, .NET has no equivalent.
 

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

Top