This Tutorial shows you how to serialize an Object
This Topic assumes that you have already studied the Topic of
Initializing Serializer (Simple)After Initializing Compiler Info
Now A Sample Object To Serialize
Public Class ToBeTester
Public Field1 = "String1"
Public Field2 = "String2"
Public Property Prop1 = 999
Public Num = Me
End Class
To serialize object you should provide a Text writer eg string writer
And also a StateWrite Which writes State Of an Object
Using sw As New StringWriter, sx As New StateWriter(s)
sx.WriteState(New ToBeTester, sw)
File.WriteAllText("Main.txt", sw.ToString)
End Using
Now When You Serialize This You Get These Results
ToBeTester{
.Field1 = System.String{
U3RyaW5nMQ==}
.Field2 = System.String{
U3RyaW5nMg==}
._Prop1 = System.Int32{
999}
.Num = #0
}
Only Modifying the Syntax You can Change Output by just changing syntax chars:-
s.Collection = "," 'The Char to separate collection items from each other
s.EndBlock = ")" 'The Char to identify the end of a block
s.StartBlock = "(" 'The Char to Identify the start of a block
s.VariableName = "$" 'The char after which variable(field) Name is written
s.VariableValue = ">" 'The Char after which value of variable(field) is written
Now results are:-
ToBeTester(
$Field1 > System.String(
U3RyaW5nMQ==)
$Field2 > System.String(
U3RyaW5nMg==)
$_Prop1 > System.Int32(
999)
$Num > #0
)
What is #0In fact During serialization each object it is added to cache so that same object should not be serialized again.