Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# Serialization
Message
From
28/06/2011 12:26:47
 
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01516342
Message ID:
01516525
Views:
54
Excellent response Viv. Much better than mine ... =0)

~~Bonnie


>>Is there any real benefit to serializing a class versus just the data the class contains?
>
>Since, from subsequent posts, it appears that you are referring to XML serialization the answer is that there isn't much difference - the XML serializer only serializes the public properties and fields of the class. If there are any such properties that you *don't* want to include then you can simply mark them with the XmlIgnore attribute. Using the standard XML serializer also allows you to shape the data to a large extent through the use of attributes.
>
>OTOH if you are serializing with the intent of reconstructing the class instance in .NET at some point then using the BinarySerializer would be preferable since it is far more compact and includes information on the class type and the assembly. But remember that if, for example, a property of the class contains a reference to another object then that class instance will also be serialized. Unless you take steps to prevent it you may end up with a unneccessarily large object graph.
>
>If you are serializing your own class it will need to be marked as serializable and implement the ISerializeable interface. Additionally any 'nested' content will need to be serializable. If you come across the need to serialize any .NET framework classes that do not implement ISerializable you can create your own methods using a SerializationSurrogate.
>
>HTH,
>Viv
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform