c# storing data in xml - how to read and write to it



I am in the process of creating a program for assigning shifts in a rota/schedule and up until now I've been using a hard coded class which contains the records for the people in it.


I'm now looking to store the data properly and was thinking xml could be a good way to do this.


I have a class Person which contains the info for the person and a class MyDataSource which creates 5 instances of the Person class and stores them in a list which I can add or remove to.


I've been looking at using the sterilization to read and write the xml files but am struggling to understand it.


Should I be able to add the code to my existing Person class or do I need to create a separate class to do this?



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;


namespace ShiftSorter
{
public class Person
{
public string name { get; set; }
public int hours { get; set; }
public int row { get; set; }
public string unit { get; set; }

/// <summary>
/// Creates a new instance of the object Person.
/// </summary>
/// <param name="newName">The name of the person</param>
public Person(string newName)
{
name = newName;
}
}
}

No comments:

Post a Comment