Solved

C# momentos for object serialization?

Posted on 2004-08-16
4
249 Views
Last Modified: 2008-03-10
I've been reading a book on C#.

When it talks about struct  (value type)  vs   class (reference type) it says:

"structs are best used for simple data types or momentos for object serialization and object state."

I don't understand the usage of "momentos" here, nor do I understand object serialization and object state.

Can someone enlighten me?
0
Comment
Question by:knowlton
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11814724
knowlton this explains the pattern which .net uses for serialization oddly enough named the momento pattern and explains what exactly a momento is http://www.ondotnet.com/pub/a/dotnet/2002/09/09/memento.html
0
 
LVL 5

Author Comment

by:knowlton
ID: 11815429
Greg:

Perfect!

Any anecdotes you can provide me regarding actual usage (by you)?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11815538
my guidelines have always been ...

1) you want deep copy behavior implicitly (valye type)
2) you are using many times over in a local context example
3) when you are not copying it around a whole bunch
4) when you are not boxing/unboxing

as for using a momento ...

lets say I have a form ... (btw this is a PERFECT example) ...

lets say it has 30 fields on it that are adjustable by the user control locations etc ...

I cannot serializae the form for various reasons

What I do is implement ISerializable and serialize out an object that contains the 30 fields ... then on deserialization I use those 30 fields to set the value (the object itself only existed for a moment ... just to copy (hence a momento))

Another reason why the above is a great example is that in order to really serialize the form I would need to serialize hundreds, maybe thousands of values when in actuality I only needed 30 as the rest will come up programatically, thus I have reduced my serialization size.

0
 
LVL 5

Author Comment

by:knowlton
ID: 11816163
Cool.

This is way over my head right now....but I'm glad to see there are some practical applications to this concept.

Tom
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
About delegates in c sharp 3 50
Error in script 11 58
send messages to whatsapp programatically 2 49
What are the simplest ways to create a Merge Sort? 3 15
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question