- archiveserialization.zip
- ArchiveSerialization.sln
- ArchiveSerialization
- ArchiveTest
- ArchiveTest.csproj
- bin
- Debug
- ArchiveSerialization.dll
- ArchiveSerialization.pdb
- ArchiveTest.exe
- ArchiveTest.pdb
- ArchiveTest.vshost.exe
- out.bin
- StarpointCommon.dll
- StarpointCommon.pdb
- Release
- ArchiveSerialization.dll
- ArchiveSerialization.pdb
- ArchiveTest.exe
- ArchiveTest.pdb
- Person.cs
- Program.cs
- Properties
- FileSystemTester
- MfcDocumentSerialization
- MfcSerialization
- bin
- Debug
- ArchiveSerialization.dll
- ArchiveSerialization.pdb
- MfcSerialization.exe
- MfcSerialization.pdb
- MfcSerialization.vshost.exe
- Release
- ArchiveSerialization.dll
- ArchiveSerialization.pdb
- MfcSerialization.exe
- MfcSerialization.pdb
- MfcSerialization.csproj
- Person.cs
- PersonList.cs
- Program.cs
- Properties
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ArchiveSerialization;
namespace ArchiveTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Boolean " + sizeof(bool));
Console.WriteLine("Double " + sizeof(double));
Console.WriteLine("Int " + sizeof(int));
Console.WriteLine("Long " + sizeof(long));
Console.WriteLine("Char " + sizeof(Char));
Console.WriteLine();
Person parent = new Person();
parent.Name = "Joe Smith";
parent.Age = 24;
parent.Sex = 'M';
parent.Weight = 123.45;
parent.Height = 1000000.0F;
parent.Birthday = DateTime.Now;
parent.Deceased = true;
Console.WriteLine("Parent GUID is {0}", parent.guid.ToString());
Person child1 = new Person();
parent.Children.Add(child1);
child1.Name = "Sallry Smith";
child1.Age = 2;
child1.Sex = 'F';
child1.Weight = 75.85;
child1.Height = 18;
child1.Birthday = DateTime.Now;
child1.Deceased = false;
Console.WriteLine("Child 1 GUID is {0}", child1.guid.ToString());
child1 = new Person();
parent.Children.Add(child1);
child1.Name = "Farry Smith";
child1.Age = 3;
child1.Sex = 'F';
child1.Weight = 22.85;
child1.Height = 4.5F;
child1.Birthday = DateTime.Now;
child1.Deceased = false;
Console.WriteLine("Child 2 GUID is {0}", child1.guid.ToString());
FileStream fsOut = File.Create("out.bin");
Archive ar = new Archive(fsOut, ArchiveOp.store);
parent.Serialize(ar);
fsOut.Flush();
fsOut.Close();
Person personIn = new Person();
FileStream fsIn = File.Open("out.bin", FileMode.Open);
Archive arIn = new Archive(fsIn, ArchiveOp.load);
personIn.Serialize(arIn);
fsIn.Close();
personIn.WriteToConsole();
MemoryStreamExample(parent);
Console.ReadLine();
}
static public void MemoryStreamExample(Person parent)
{
Console.WriteLine("");
Console.WriteLine("---------------------");
Console.WriteLine("Memory Stream Example");
MemoryStream msOut = new MemoryStream();
Archive ar = new Archive(msOut, ArchiveOp.store);
parent.Serialize(ar);
msOut.Flush();
byte[] bytes = msOut.GetBuffer();
msOut.Close();
MemoryStream msIn = new MemoryStream(bytes);
Person personIn = new Person();
Archive arIn = new Archive(msIn, ArchiveOp.load);
personIn.Serialize(arIn);
msIn.Close();
personIn.WriteToConsole();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Bob Pittenger is founder and President of Starpoint Software Inc. He holds a B.A. degree from Miami University, M.S. and Ph.D. degrees from Purdue University, and an MBA from Xavier University. He has been programming since 1993, starting with Windows application development in C++/MFC and moving to C# and .NET around 2005 and is a .NET Microsoft Certified Professional Developer.
Bob is the author of two books:
Billionaire: How the Ultra-Rich Built Their Fortunes Through Good and Evil and What You Can Learn from Them
and
Wealthonomics: The Most Important Economic and Financial Concepts that Can Make You Rich Fast.
Visit http://www.billionairebook.net for more information.