Dependant custom serialization

G

Guest

Hi
I wish to implement my own serialization scheme, so I implemented ISerializable, and added the needed functions
GetObjectData(..), and the special constructor
The thing is: I need to make a runtime decision inside these functions, and on a given case - let dotnet's regular mechanism do the work for me
Is it possible to redirect the runtime from inside these functions, to do his "usual stuff" as if I did not implement ISerializable
Thank you
Yair.
 
E

Eric Eggermann

Yair said:
Hi,
I wish to implement my own serialization scheme, so I implemented
ISerializable, and added the needed functions:
GetObjectData(..), and the special constructor.
The thing is: I need to make a runtime decision inside these functions,
and on a given case - let dotnet's regular mechanism do the work for me.
Is it possible to redirect the runtime from inside these functions, to do
his "usual stuff" as if I did not implement ISerializable?
Thank you,
Yair.

Well, by implementing ISerializable, you're saying that you're going to do
it yourself. But the following could work perhaps in the GetObjectData
routine.

Type thisType = this.GetType();
MemberInfo[] mi = FormatterServices.GetSerializableMembers(thisType,
context);

for (Int32 i = 0 ; i < mi.Length; i++)
{
info.AddValue(mi.Name, ((FieldInfo) mi).GetValue(this));
}

then pretty much the same code in the special constructor.

But, it's very likely that using two different ways of serializing your
object will make them incompatible. Look at this MSDN article, and the two
that follow it,
http://msdn.microsoft.com/msdnmag/issues/02/04/net/

The code I pasted above, is pretty much taken from the article.

HTH
Eric
 

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