Today looked under the code of a previous tool, which involves. NET class for serialization and deserialization, so just write about it.
Here, say something. NET class Serialization Benefits: NET classes are only a relatively narrow class before they are serialized. By serialization, it is better to save the form of the class, and to better save the contents of the class through XML. By deserializing the class, we are better able to get the content of the class, and better to access the contents of the class through the way of XML operation.
Let's take a look at the method of class serialization.
There are two methods available here. The first method is simple, passing directly to an object, and then using the XmlSerializer class to get the contents of the class, preparing for the serialization below. The object is then serialized into textual form by StringWriter's Serialize method.
The second method is also very simple, by passing in an array of objects, and the type of an object array, and then, again, by StringWriter's Serialize method, the object array is serialized as text.
Let's take a look at the deserialization method.
There are three methods available here. The first method is simple, by passing in the object type, and the string of text that has been serialized by the object, by TextReader the deserialize method to convert the text content into the form of a class.
The second method is also very simple, passing directly to the object type and the text content that has been serialized enough, as well as converting the text content into the form of a class by TextReader's deserialize method.
The third method is also very simple, by passing in the form of an array of types, as well as the object array type and the type of content to be processed, and finally through the TextReader deserialize method to convert the text content into the form of a class.
With the code above, we can see a simple way to serialize and deserialize. Let's talk about the code we'll use here.
The above is a code used to serialize the contents of a configured object into XML and then save it.
Here's another look at deserialization.
Above, the serialized user configuration is deserialized into an object, and then the object can be manipulated. Saves a lot of action and saved content.
By the above description, it is estimated that everyone has been right. NET class has a concept of serialization and deserialization, we can see the benefits of serializing and deserializing objects. Similarly, we are able to save the serialized content to the database and then use it to deserialize the object in the form of a read database. The above is only processed in the form of saving the object as a file.
The two class files used above are provided for use by the person in need.
Http://files.cnblogs.com/lzhdim/%E5%BA%8F%E5%88%97%E5%8C%96%E5%92%8C%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96.rar
Ps. Today is Sunday, I this sunny, hope my content can let the winter temperature change can make the opposite of you feel warm.
. NET class serialization and deserialization-Advanced series-Learner series articles