Hello.
In this video, we're going to talk about Question 18.
What is civilization?
Civilization is the process of converting an object into a format that can be stored in memory or transmitted
over a network.
For example, the object can be converted into a text file containing Dyson or Azimo or a binary file.
This realization is the opposite process using the content of a file to recreate objects.
All right.
Here is a simple program that simply reads some input from the user.
It uses this input to build a person object.
Here is what I would like us to do after this program is run for the first time and the personal data
is read.
I would like to store the person object in memory, for example, as a text file with example if we
run this program for a second time.
It shouldn't ask those questions again.
It should read this data from the XML file and build the person object.
All right, so let's do it.
We'll start by writing a method that serialize is a person and convert it into a string, which will
later be the content of the XML file.
There is no point in reinventing the wheel, so we'll use the built in Xmas sterilizer class.
Let's see what happened here.
The Maximo serializing across serialize is the object it takes as a parameter and writes the results
thrilling to the Examiner writer.
I created this writer with settings saying that the result would be indented, so it looks more readable
in the text file.
Let's see if it works.
And here is the exam result seems like our civilization is working, what we need to do now is save
it to an ExxonMobile.
Let's make sure it works.
I'm going to check if the file has been saved to the output folder.
And here it is, seems like the saving of the civilized object works.
Alright, so what we want to do now is when the application starts, we should check if such a file
exists.
If so, instead of building the person object based on the user's answers, we should just build it
from the data stored in the file.
We'll start by reading the existing file and then will decrease its content.
All right.
Similarly, as before.
I'm just using the existing classes first.
I'm reading the file with the screen reader and I'm building a special example text reader from it.
Finally, I'm using the example centralized to decentralized, the text that has been read and built
a person object from it.
Let's make sure it works.
All right.
Looking good in this simple program, we used the example serialization, but there are different formats.
One of the most common formats is Jason.
The name comes from JavaScript object notation because it derives from JavaScript objects format.
Jason is typically used for communication over a network, for example, when you fill a form on a website.
Most likely, the data from the form is wrapped in JSON format and sent to the server, which then reads
it and translate it to see sharp objects.
Of course, assuming the backend is written C-sharp, this is how the data we thought as an example
would look like in JSON format.
If you want to your and decentralize objects using day soon, I recommend using Jason does not library.
Developed by Newton Soft in the resources attached to this lecture, I'm showing serialization and disassociation
using this library.
One more thing that we should mention on this topic.
The interviewer can ask you What does the serial zebu attribute to do?
First, let me show you how it looks.
Some people think this attribute must be added to a type if we want to serialized it to example or JASON
format.
But actually, this is not correct.
This attribute indicates that instances of a type can be serialized with binary formatter or soap formatter.
It is not required, for example, adjacent serialization.
The binary, for matter, symbolizes this object to a binary format, so simply speaking, a chain of
zeros and ones.
The soap formatter uses the soap format, which is a little similar to the example.
Let's summarize Serialization is a process of translating objects into a format that can be stored as
a file and possibly transmitted over a network.
Serialized objects can later be reconstructed.
The interview questions related to this topic could be what are uses of civilization to send objects
over on network or to store objects in the fire for later reconstruction, or even to store them in
a database?
This is sometimes done to save a snapshot of an object.
Every time I use it to make some changes to it so we can log the history of the objects tenders.
What does the serialized attribute to?
This attribute indicates that instances of a type can be serialized with binary from water or soap,
for matter.
It is not required, for example, or decentralization.
What is this realization?
This realization is the opposite of the realization.
It's using the content of a file to recreate objects.
All right, that's it.
About serialization.
Thanks for watching and see you in the next lecture.