Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

C# momentos for object serialization?

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?
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

Greg:

Perfect!

Any anecdotes you can provide me regarding actual usage (by you)?
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.

Cool.

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

Tom