PDA

View Full Version : Serialization in .NET



cronodragon
02-10-2007, 03:30 PM
This is another doubt I have. Is it possible to store and retrieve different data types from locations in memory?

VilleK
02-10-2007, 07:02 PM
How do you mean?

.NET has very good built-in serialization to and from XML:
System.Xml.Serialization.XmlSerializer (http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx)

If you want to write your own you can use reflection to enumerate and read fields from a class.

cronodragon
02-10-2007, 07:15 PM
How do you mean?

.NET has very good built-in serialization to and from XML:
System.Xml.Serialization.XmlSerializer (http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx)

If you want to write your own you can use reflection to enumerate and read fields from a class.

Well, I think I'm looking for something like the BitConverter:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystembitconverterclasstopic.asp

I'm taking a look at it, and it doesn't have a toExtended method... Is that floating-point type not available in .NET?

Anyway, that "reflection" concept you wrote sounds interesting, is there more information on that? Thanks!

VilleK
03-10-2007, 07:17 AM
Anyway, that "reflection" concept you wrote sounds interesting, is there more information on that? Thanks!

So you want to stream to a binary format? Should be possible although I haven't tried that.

I found this:
System.Runtime.Serialization.Formatters.Binary Namespace
http://msdn2.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.asp x
"The System.Runtime.Serialization.Formatters.Binary namespace contains the BinaryFormatter class, which can be used to serialize and deserialize objects in binary format."

System reflection-namespace:
http://msdn2.microsoft.com/en-us/library/system.reflection.aspx

Also Google for "system reflection" to find articles about it.