I have a class with a number of fields that has been saved in previous versions of my app. I refactored the class and have changed the type of one of the fields of the class from an int to an object. When I try loading the save file, it fails due to a FormatException which I expected. I created a custom type for the class so that I could process the field for either case (if it was an int or an object) but I am struggling to get something workable.
Code: Select all
...
case "_propertyName":
try
{
var newType = reader.Read<System.Collections.Generic.List<MyObject>>();
reader.SetPrivateField("_propertyName", newType , instance);
}
catch (Exception e)
{
var oldType = reader.Read<System.Collections.Generic.List<int>>();
var convertedType = oldType .Select(x => new MyObject(x)).ToList();
reader.SetPrivateField("_propertyName", convertedType , instance);
}
break;
...