Game Development Reference
In-Depth Information
}
}
}
return null;
}
catch (Exception)
{
return null;
}
}
Implementation for Serializable Objects
A powerful feature of the .NET platform is the ability to serialize objects into an
XML or binary representation to make storing, sending, or transforming data
extremely easy. Serialization is common practice and is used in many facets of
.NET application or systems development. The BinaryFormatter class can serialize
and deserialize data into a stream, which makes GZipStream a suitable target for
data transformation.
The first step is to include the appropriate namespaces.
using System;
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization.Formatters.Binary;
The following code describes a simple serializable class that is used in the accom-
panying example for this chapter. It shows how to create a serializable class and
properly decorate it with the SerializableAttribute .
[Serializable]
internal class TestObject
{
private string testString;
private int testInteger;
public string TestString
{
get { return testString; }
set { testString = value; }
}
Search Nedrilad ::




Custom Search