1. Overview
Transfer data between applications, you need to first convert the data object into a character stream or byte stream form, and then the receiving side will receive and then convert back to the original data object. This is serialization and deserialization.
This chapter describes serialization and deserialization in. NET, the kind of serializer, and configuration objects for serialization.
2. Main content
2.1 Serialization and deserialization
Serialization can only hold data parts of an object and cannot save a method part. You can create a custom data transfer object (DTO) to save only the information that you specify.
The. NET platform provides three types of serialization:
①xmlserializer:
[Serializable] PublicclassPerson { PublicstringFirstName {Get;Set; } PublicstringLastName {Get;Set; } PublicintAge {Get;Set; } }xmlserializer Serializer=NewXmlSerializer (typeof(person)); stringXML;using(StringWriter StringWriter =NewStringWriter ()) {Person P=NewPerson {FirstName="John," LastName.="Doe", Age= the }; Serializer. Serialize (StringWriter, p); XML=stringwriter.tostring ();} Console.WriteLine (XML); using(StringReader StringReader =NewStringReader (XML)) {Person P=(person) serializer. Deserialize (StringReader); Console.WriteLine ("{0} {1} is{2} years old ", P.firstname, P.lastname, p.age); }
Available attribute:
Not to be continued.
Chapter 21st serialization of data access (in. net4.5)