Q:

XML Deserialization

I have an xml file which is in this format
"<rundate>

  <rundateItem>
    <LeaveCreditingMonth>2</LeaveCreditingMonth>
    <LeaveCreditingYear>2010</LeaveCreditingYear>
    <IncludeNoTimesheet>True</IncludeNoTimesheet>
  </rundateItem>

</rundate>"

in case i want to deserialize this xml file, what should be the format of the class or the target object of my deserialization?
Currently my class looks like this:
public class rundate
    {

        string _leaveCreditingMonth;
        string _leaveCreditingYear;
        string _includeNoTimesheet;

        public string LeaveCreditingMonth {get{return _leaveCreditingMonth;}set{ _leaveCreditingMonth = value;}}
        public string LeaveCreditingYear {get{return _leaveCreditingYear;}set{ _leaveCreditingYear = value;}}
        public string IncludeNoTimesheet {get{return _includeNoTimesheet;}set{ _includeNoTimesheet = value;}}

    }

A:

Your class can stay as is (obviously you should change the data types to be appropriate though) - since you have rundate nested in your XML (which implies there can be more than one) I would suggest adding a collection class as follows:
[XmlRoot("rundate")]
public class RundateCollection
{
    [XmlElement("rundateItem")]
    public List<rundate> Rundates { get; set; }
}

You can test serializing/deserializing your class with your XML as follows:
XmlSerializer serializer = new XmlSerializer(typeof(RundateCollection));
StringWriter sw = new StringWriter();
rundate myRunDate = new rundate() { LeaveCreditingMonth = "A", IncludeNoTimesheet = "B", LeaveCreditingYear = "C" };
RundateCollection ra = new RundateCollection() { Rundates = new List<rundate>() { myRunDate } };
serializer.Serialize(sw, ra);
string xmlSerialized = sw.GetStringBuilder().ToString();
string xml = File.ReadAllText(@"test.xml");
StringReader sr = new StringReader(xml);
var rundateCollection = serializer.Deserialize(sr);

You will see that the collection class is successfully deserialized from your XML and contains one list item of type runlist.

