static void Main(string[] args) { List<Employee> list = new List<Employee>(6); Employee Employee1 = new Employee(1, "John"); Employee Employee2 = new Employee(2, "Jane"); list.Add(Employee1); list.Add(Employee2); list.Add(Employee1); FileStream writer = new FileStream("sample.xml", FileMode.Create); DataContractSerializer ser = new DataContractSerializer( type: typeof(List<Employee>), rootName: "root", rootNamespace: "rootns", knownTypes: null, maxItemsInObjectGraph: int.MaxValue, ignoreExtensionDataObject: false, preserveObjectReferences: true, // false is default value dataContractSurrogate: null); ser.WriteObject(writer, list); writer.Close(); }
static void Main(string[] args) { Employee e = new Employee(101, "John"); FileStream writer = new FileStream("sample.xml", FileMode.Create); DataContractSerializer ser = new DataContractSerializer(typeof(Employee)); ser.WriteObject(writer, e); writer.Close(); }
public static Model.Employee ToDomainModel(this DataContract.Employee employee) { if (employee == null) { return(null); } return(new Model.Employee() { Id = employee.Id, Title = employee.Title, FirstName = employee.FirstName, LastName = employee.LastName, Email = employee.Email, JoiningDate = employee.JoiningDate, Phone = employee.Phone, Roles = employee.Roles }); }