Serialize .NET Classes With Inheritance To XML In C#
Good day! Here's a simple example on how to Serialize .NET classes that applied the concept of Inheritance to XML. Given the model classes below: [Serializable] public class Employee { public int EmployeeId { get ; set ; } public string Name { get ; set ; } public string Address { get ; set ; } } [Serializable] public class Utility : Employee { public string Category { get ; set ; } } [Serializable] public class Supervisor : Employee { public int OverrideCode { get ; set ; } } The code to populate and serialize the objects to XML is presented here using XmlSerializer class: List<Employee> employees = new List<Employee>(); Supervisor supervisor1 = new Supervisor(); supervisor1.Name = "Michael" ; supervisor1.Address = "Manila" ; supervisor1.EmployeeId = 11111; supervisor1.OverrideCode = 234; employees.Add(supervisor1); Utility utility1 = new Utility(); utility1.Name = "Erick" ; utility1.Address = "Masba...