By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,888 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,888 IT Pros & Developers. It's quick & easy.

extending serialization

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
"Aaron Clamage" <ac******@nospam.cs.umd.edu> wrote in message
news:#T**************@TK2MSFTNGP11.phx.gbl...
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

Nov 15 '05 #2

P: n/a
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

"Aaron Clamage" <ac******@nospam.cs.umd.edu> wrote in message
news:eN****************@TK2MSFTNGP09.phx.gbl...
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
"Aaron Clamage" <ac******@nospam.cs.umd.edu> wrote in message
news:#T**************@TK2MSFTNGP11.phx.gbl...
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


Nov 15 '05 #3

P: n/a

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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...alTOC.doc.html

AFAIK, .NET has no equivalent.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.