Содержание
- 2. Agenda What is Serialization? Serialization in .NET Binary serialization Custom serialization XML Serialization in C# Using
- 3. What is Serialization? Serialization is the process of transforming an object or object graph that you
- 4. Serialization in .NET
- 5. Serialization in .NET .NET Framework has classes (in the System.Runtime.Serialization and System.Xml.Serialization namespaces) that support: binary,
- 6. Binary serialization In binary serialization all items are serialized, even private field and read-only, increasing productivity.
- 7. BinaryFormatter [Serializable] class Person { private int _id; public string FirstName; public string LastName; public void
- 8. To indicate that instances of this type can be serialized, mark it with the [Serializable] attribute.
- 9. Custom serialization. ISerializable With a custom serialization, you can specify exactly which objects will be serialized,
- 10. ISerializable. Example of implementation [Serializable] public class Person : ISerializable { private int _id; public string
- 11. Custom serialization. Using attributes Add attribute before a custom method that manipulates the object’s data during
- 12. XMLSerializer The XmlSerializer (namespace System.Xml.Serialization) was created with the idea of Simple Object Access Protocol (SOAP)
- 13. XMLSerializer To deserialize an object: Construct a XmlSerializer using the type of the object to deserialize.
- 14. XMLSerializer You can configure how the XmlSerializer serializes your type by using attributes. These attributes are
- 15. Complex and derived types serialization [Serializable] public class Person { public string FirstName { get; set;
- 16. Complex and derived types serialization private static Order CreateOrder() { Product p1 = new Product {
- 17. Using DataContract DataContract is used when you use WCF. The DataContractSerializer is used by WCF to
- 18. Using DataContract [DataContract] public class PersonDataContract { [DataMember] public int Id { get; set; } [DataMember]
- 19. Using DataContract PersonDataContract p = new PersonDataContract{ Id = 1, Name = “John Doe”}; using (Stream
- 20. NetDataContractSerializer Diffrence between DataContractSerializer and NetDataContractSerializer is that the NetDataContractSerializer passes type information in the XML
- 21. JSON Serialization We can use DataContractJsonSerializer to serialize type instance to JSON string and deserialize JSON
- 22. Demonstration 4. Json Serialization. class Person [DataContract] internal class Person { [DataMember] internal string name; [DataMember]
- 23. Demonstration 4. Json Deserialization. class Person stream1.Position = 0; Person p2 = (Person)ser.ReadObject(stream1); Console.Write("Deserialized back, got
- 24. JSON Brief Introduction JSON (JavaScript Object Notation) is one lightweight data exchange format. JSON is "name/value"
- 26. Скачать презентацию