Hello,
i know thats a very common Topic, but i dit not find any Solution.
lets say i change a Class:
<pre lang="x-c#"> class MyClass
{
private List<string> m_SomeStrings;
public List<string> SomeStrings
{
get { return m_SomeStrings; }
set { m_SomeStrings = value; }
}
#region a lot of other methods
}
and replace the Member SomeStrings with a more Specialiced Collection,
i run, of course, into some backward compabtibility issues:
class MyClass
{
private MySuperCollection m_SomeStrings;
public MySuperCollection SomeStrings
{
get { return m_SomeStrings; }
set { m_SomeStrings = value; }
}
#region a lot of other methods
}
class MySuperCollection : Collection<string>
{
}
The Question is now:
"Whats the easiest way to solve that Issue"
i hoped that i hase just to append a TypeConverter - since there must be a logic that converts the old Type into the new Type,
class SuperTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
//check if possible...
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
//do some clever convertion...
}
.
.
.
}
[TypeConverter(typeof(SuperTypeConverter)]
class MySuperCollection : Collection<string>
{
}
but the BinaryFormatter throws an Exception "List<string> not convertable to MySuperCollection.
The next idea has been to implement this behavior as ISerializationSurrogate, something like a TypeConverterAwareSerializationSurrogate, but got pretty confused doing so,
so i am unsure now if i am on the correct way.
So the final querstion is:
Whats the most correct way to provide Backward compatibility in this specific scenario (The Type of a field changes to a compatible Type)