I am attempting to parse an xml string that has dates in there. The object that I am trying to fill has a nullable DateTime. But if the string that I pull back has an empty value, I want it to be the min Date Value. and I want to assign that to the variable? Is there a simple way to do that using LINQ
IEnumerable<PatientClass> template = (IEnumerable<PatientClass>)(from templates in xDocument.Descendants("dataTemplateSpecification")//elem.XPathSelectElements(string.Format("//templates/template[./elements/element[@name=\"PopulationPatientID\"and @value='{0}' and @enc='{1}']]", "1", 0))
select new PatientClass
{
PCPAppointmentDateTime = DateTime.Parse(templates.Descendants("element").SingleOrDefault(el => el.Attribute("name").Value == "PCPAppointmentDateTime").Attribute("value").Value),
});
The object that I am using is this…
class PatientClass
{
public DateTime? PCPAppointmentDateTime { get; set; }
}
Any ideas?
You should wrap
Parsein a method. Return aDateTime.