D
Dylan Nicholson
Hello,
I have an issue where I've replaced a single class field with a number
of separate fields that allow more fine control. The problem is that
my old files, saved using XmlSerialization, still have this old field
name in them, and I need to be able to read it and set the new fields
appropriately.
E.g. the if the old class
class MyClass
{
public int area;
}
and the new version is now
class MyClass
{
public int width;
public int height;
}
then when executing:
XmlTextReader xmlReader = new XmlTextReader(filename);
XmlSerializer xs = new XmlSerializer(typeof(MyClass));
MyClass obj = (MyClass)xs.Deserialize(xmlReader);
I need to be able to look for the "area" value in old files, and set
width and height appropriately (e.g. to the square root of the area
value).
Is there a straightforward way of doing this?
Note the class has at least 30 other members, and that I'm using a
generic piece of code to do the actual serialization that's not
specific to MyClass, though of course I can put a test in to deal with
MyClass as a special case if necessary.
I have an issue where I've replaced a single class field with a number
of separate fields that allow more fine control. The problem is that
my old files, saved using XmlSerialization, still have this old field
name in them, and I need to be able to read it and set the new fields
appropriately.
E.g. the if the old class
class MyClass
{
public int area;
}
and the new version is now
class MyClass
{
public int width;
public int height;
}
then when executing:
XmlTextReader xmlReader = new XmlTextReader(filename);
XmlSerializer xs = new XmlSerializer(typeof(MyClass));
MyClass obj = (MyClass)xs.Deserialize(xmlReader);
I need to be able to look for the "area" value in old files, and set
width and height appropriately (e.g. to the square root of the area
value).
Is there a straightforward way of doing this?
Note the class has at least 30 other members, and that I'm using a
generic piece of code to do the actual serialization that's not
specific to MyClass, though of course I can put a test in to deal with
MyClass as a special case if necessary.