|
using System;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
namespace Personalisation
{
/// <summary>
/// Class that resolves deserialisation problems.
/// Also useful to make sure most recent version of the ColumDetails is used even if the serialised version was stored against an old version.
/// If the ColumnDetails structure changes then this can be used to switch versions.
/// </summary>
internal sealed class ColumnDetailsDeserialisationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
// For each assemblyName/typeName that you want to deserialize to
// a different type, set typeToDeserialize to the desired type.
String assemblyVersion = Assembly.GetExecutingAssembly().FullName;
String columnDetaisTypeName = typeof(ColumnDetails).FullName;
if (assemblyName != assemblyVersion && typeName == columnDetaisTypeName)
{
// To use a type from a different assembly version,
// change the version number.
// To do this, uncomment the following line of code.
assemblyName = assemblyVersion; //assemblyName.Replace("1.2.0.0", "2.0.0.0");
// To use a different type from the same assembly,
// change the type name.
//typeName = "Version2Type";
}
// The following line of code returns the type.
Type typeToDeserialise = Type.GetType(String.Format(CultureInfo.InvariantCulture, "{0}, {1}", typeName, assemblyName));
return typeToDeserialise;
}
}
}
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.