日付があるxml文字列を解析しようとしています。私が埋めようとしているオブジェクトにはnull可能なDateTimeがあります。しかし、私が元に戻す文字列に空の値がある場合は、それを最小の日付値にします。それを変数に代入したいのですか? LINQDateTime.Min文字列がEmptyOrと等しい場合の値LinqからXMLへのヌル
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),
});
オブジェクトを使用して、私が使用していることがこれであることを行うための簡単な方法は...
class PatientClass
{
public DateTime? PCPAppointmentDateTime { get; set; }
}
任意のアイデアがありますか?
はなぜ魔法の値ではなくnullを使用していないが? – rerun
興味がありません。ヌルを利用できるときに、なぜあなたは 'DateTime.MinValue'を使用しますか?ヌル値を使用することが決してできない場合は、なぜそれをnullableで始めるのが気になるのですか? –