How to serialize and deserialize C# object to Binary Format | Binary Serialization/Deserialization | HCoder
In this video, we are discussing about how to serialize C# objects to Binary format data file and also how to deserialize the serialized binary data back to C# objects
These constructs are used in every day application like the text editor maintaining it's state of how many files are in open, what files are yet to be saved, what are
the recently closed files and so on.
We make use of BinaryFormatter available in using System.Runtime.Serialization.Formatters.Binary namespace. Since we are writing to a Binary File, we used FileStream class to do the writing and we used stream while
reading the binary data back to the program. We used existing application to demonstrate serialization and deserialization.
The source code is available in git in this path https://github.com/HCoderWorld/LearnC...
We go about saving the User details from the form to a separate class and we write SerializeBinary method and DeserializeBinary method in the User class.
Then we demonstrate how the data entered into the form is taken as User object which is then serialized to binary file. Also we were able to
deserialize and load the data from binary file to user object which eventually gets loaded into the form.
Then we introduce fields that can be ignored during serialization by marking it with the decorator NonSerialized. This would make the program ignore the fields while writing to
the binary file. And we also mark the fields as Optional using the decorator OptionalField. This would make the binary formatter to use some default values for those optional
fields. Then we explore using the decorator OnDeserializing and OnDeserialized which is used to mark methods to call them before and after deserialization respectively.
These methods then can be used to fill in Optional Fields and Ignored Fields
Subscribe to this channel for more programming videos. This channel covers project tutorials and certain solutions for scenarios like this.
Ask your doubts in the comment section.
How to serialize and deserialize C# object to Binary Format,Serialization in C#,Deserialization in C#,Binary Format, Binary Serialization C#, Binary Deserialization C#,C# Tutorials, HCoder,
BinaryFormatter,System.Runtime.Serialization.Formatters.Binary,FileStream,C# to Binary,Binary File,Convert C# object to Binary,serialize and deserialize in C# Binary, BinaryFormatter.Serialize,BinaryFormatter.Deserialize
Save C# to Binary File,OnDeserializing,OnDeserialized,NonSerialized,OptionalField,Ignore Fields in Binary file C#,Optional Fields in Binary Serialization C#
Auf dieser Seite können Sie das Online-Video Serializing/Deserializing C# object to Binary Format | Binary Serialization/Deserialization | HCoder mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer HCoderPro 01 Januar 1970 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,439 Mal angesehen und es wurde von 22 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!