[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Question about Serialization.

I have a question to the sample code in MSDN regarding Serialization:
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeserializationformattersbinarybinaryformatterclassserializetopic.asp)

In the code:
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, addresses);

But the Serialize method is a virtual overloaded method. And I couldn't find the real implementation of the Serialize().

So where is the real implementation of the Serialize() method?

I think my question came from not knowing level details of the Serialization. Anybody can clarify this? Many thanks!
0
heyday2004
Asked:
heyday2004
3 Solutions
 
BurntSkyCommented:
I'm not quite sure I understand what your question is.  You're saying the BinaryFormatter.Serialize() method is overloaded?  That just means there is more than one way to call the method (more than one acceptable signature).  Either one of them is the "real implementation" of the Serialize() method.  The BinaryFormatter class implements two interfaces: IRemotingFormatter and IFormatter.  The specifications for these interfaces require the class to implement a Serialize() method.
0
 
TheAvengerCommented:
The implementation of the Serialize method is in the BinaryFormatter class. It uses the binary presentation of the argument to serialize it in the underlying stream. The objects to be serialized must always be marked with the [Serializable] attribute.
0
 
nachiketCommented:
To add to TheAvenger's comment. As an option You can choose how you want to serialize your class. For that you need to implement ISerializable interface.

One more thing. The virtual method means it will(should) have default implementation however you can give your own implementation is you want to do that. so BinaryFormatter already has the implementation but if u want to use your own formater you can override Serialize method.

Regards
Nachiket Shah
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now