Information Technology Reference
In-Depth Information
[
NonSerialized
]
private int
value;
private
OtherClass
otherThing;
private const int
DEFAULT_VALUE =
5
;
private int
value2;
// public constructors elided.
// Protected constructor used only by the
// Serialization framework.
protected
MyType(
SerializationInfo
info,
StreamingContext
cntxt)
{
label = info.GetString(
"label"
);
otherThing = (
OtherClass
)info.GetValue(
"otherThing"
,
typeof
(
OtherClass
));
try
{
value2 = info.GetInt32(
"value2"
);
}
catch
(
SerializationException
e)
{
// Found version 1.
value2 = DEFAULT_VALUE;
}
}
[
SecurityPermissionAttribute
(
SecurityAction
.Demand,
SerializationFormatter =
true
)]
void
ISerializable
.GetObjectData(
SerializationInfo
inf,
StreamingContext
cxt)
{
inf.AddValue(
"label"
, label);
inf.AddValue(
"otherThing"
, otherThing);
inf.AddValue(
"value2"
, value2);
WriteObjectData(inf, cxt);
}