I've had a class which looked like
public class MyClass
{
public string EmployerName;
public string EmployerSurname;
public string EmploeeName;
public string EmploeeSurname;
}
I've refactored the code above to this:
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;
}
}
Problem is, that when deserializing XMLs, which were serialized from old class version, I hoped that the new properties would work, and fields of the inner objects would be filled, but they don't.
Any ideas how, besides implementing IXmlSerializable, I could modify the new class to support both new and old versions of XMLs? Or maybe IXmlSerializable is the only way?