Information Technology Reference
In-Depth Information
private const int Version1_0 = 0x0100 ;
private const int Version1_1 = 0x0101 ;
private const int Version1_2 = 0x0102 ;
// major release:
private const int Version2_0 = 0x0200 ;
// check for the current version:
private static readonly int CurrentVersion =
Version2_0;
Yo u u s e t h e r u n t i m e v e r s i o n t o s t o r e t h e c u r r e n t v e r s i o n i n e a c h s a v e d fi l e :
// Read from persistent storage, check
// stored version against compile-time constant:
protected MyType( SerializationInfo info,
StreamingContext cntxt)
{
int storedVersion = info.GetInt32( "VERSION" );
switch (storedVersion)
{
case Version2_0:
readVersion2(info, cntxt);
break ;
case Version1_1:
readVersion1Dot1(info, cntxt);
break ;
// etc.
}
}
// Write the current version:
[SecurityPermissionAttribute(SecurityAction.Demand,
SerializationFormatter = true )]
void ISerializable.GetObjectData(SerializationInfo inf,
StreamingContext cxt)
{
// use runtime constant for current version:
inf.AddValue( "VERSION" , CurrentVersion);
// write remaining elements...
}
 
Search WWH ::




Custom Search