Saturday, February 23, 2019
Store and Recover Information About Object Using Binary Serialization in C#
Report Store and Recover In coiffeion close to Object Using double star serialisation in C What is binary star serialisation Serialization is the process taking an object and converting it to a format which heap be transported through net work or breed into a storage medium, the storage medium could be file, database, or memory. The . lettuce Framework provides two types of serialization, XML serialization and Binary serialization. There be overly three formats provided by the Microsoft . NET framework to which objects can be serialized. The formats argon binary, grievous bodily harm, and XML.Binary serialization can either the binary or the SOAP formatter, are suitable for storing object Information in . NET finishs, and you dont need share the information with non-. NET programs. When I mention Binary serialization below I mean Binary serialization delectation binary formatter, as short expression. Why use Binary Serialization The binary serialization working chart is pic The chart also can present the other two format of serialization. so why we use Binary serialization instead of use the other two? What the advantage and disadvantage of binary serialization?The binary serialization is the most bundle up and light of the three formats and it is the fastest one of the three formats. Also the binary serialization can serialize all the state of the object, including type information. so when the object is deserialized, you get an accurate and fully functional copy of the original, which xml testament non It ignores private member fields and properties. The main limitation of utilize binary serialization is that binary serialization depends on platform, while XML and SOAP do not adhere to that limitation.Therefore only when all your applications which use serialization are . net framework applications, you can use binary serialization, differently uses other two formats instead. Using Binary Serialization in C The tag to using Binary seriali ze is very simple. The step is 1) frame an instance of an BinaryFormatter class (using the interface iForamatter) 2) dedicate it an object and an open spud 3) iFormatter. Serialize methodwrites the objects state to the stream. Below I will show a very simple grave to serialize an object call a someone to a file.To make a class serializable we must mark it with the serializable attribute at before the class code The code is Serializable public class somebody then we need 2 namespaces for using serialization in our application using System. Runtime. Serialization. Formatters. Binary using System. Runtime. Serialization then use the code below to Serialize // give an instance of an BinaryFormatter class(IFormatter is a interface) IFormatter formatter = new BinaryFormatter() //create a stream Stream stream = new FileStream(filename, FileMode. Create, FileAccess.Write, FileShare. None) //pass stream and object to the stream formatter. Serialize method for doing Serialization formatte r. Serialize(stream, aPerson) // immaculate close the stream stream. Close() The deserialize just as simple as serialize, the code are IFormatter formatter = new BinaryFormatter() Stream stream = new FileStream(MyFile. dat, FileMode. Open, FileAccess. Read, FileShare. Read) Person clone = (Person) formatter. Deserialize(stream) stream. Close() Some Important not for Serialization ? the constructors are not called when an object is deserialized. the Serializable attribute cannot be inherited. ? there are some security measures issues of serialization you can visit The Security and Serialization (http//msdn. microsoft. com/library/? universal resource locator=/library/en-us/cpguide/html/cpconsecurityserialization. asp viper)topic in the Framework Documentation further drill This report just explains the very basic idea of Binary serialization for further study the following links will help. Serializing Objects http//msdn. microsoft. com/library/default. asp? universal resource locat or=/library/en-us/cpguide/html/cpovrSerializingObjects. sp C Object Serialization by Budi Kurniawan http//www. ondotnet. com/pub/a/dotnet/2002/08/26/serialization. html References Serializing Objects http//msdn. microsoft. com/library/default. asp? url=/library/en-us/cpguide/html/cpovrSerializingObjects. asp http//www. c-sharpcorner. com/Language/serializingObjectsinCS. asp Deserialization Binary Serialization network Deserialization Binary Serialization Copy of Your Object A File, Database or memory Storage medium Another operation Your object Your Application
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment