I had a class that looked like
public class MyClass { public string EmployerName; public string EmployerSurname; public string EmploeeName; public string EmploeeSurname; }
I reworked the code above:
public class MyClass { public MyClass() { Employer = new PersonInfo(); Emploee = new PersonInfo(); } public class PersonInfo { public string Name; public string Surname; } public PersonInfo Emploee; public PersonInfo Employer; [Obsolete] public string EmploeeName { get { return Emploee.Name; } set { Emploee.Name = value; } } [Obsolete] public string EmploeeSurname { get { return Emploee.Surname; } set { Emploee.Surname= value; } } [Obsolete] public string EmployerName { get { return Employer.Name; } set { Employer.Name = value; } } [Obsolete] public string EmployerSurname { get { return Employer.Surname; } set { Employer.Surname = value; } }
The problem is that when deserializing XML that was serialized from an old version of the class, I was hoping that the new properties would work and the fields of the internal objects would be populated, but they didn't.
Any ideas on how, besides implementing IXmlSerializable, I could change the new class to support both new and old versions of XML? Or maybe IXmlSerializable is the only way?
source share