Based on date, get todays and the next two days values from XML?

后端 未结 1 1282
滥情空心
滥情空心 2021-01-26 15:40

Goal: Based on todays date and month, get actual and the next two days values from XML.

Issue: Although my c.Attribute(\"Day\").Value changes, my c.Attribute(\"Month\").

相关标签:
1条回答
  • 2021-01-26 16:11

    I would suggest you change your "model" class to use DateTime instead of string for the date. Transform all the elements into your model class, and then filter. It'll be a lot simpler than trying to do arithmetic based on the attributes.

    Also note that using the explicit conversions from XAttribute is simpler than calling int.Parse everywhere. I would actually suggest creating a static FromXElement method in your model class, so you can write:

    DateTime start = DateTime.Today;
    // We'll use this as an *exclusive* upper bound
    DateTime end = start.AddDays(3);
    
    var query = from c in loadedCustomData.Descendants("PrayerTime")
                let bonn = Bønn.FromXElement(c)
                where bonn.Dato >= start && bonn.Dato < end;
                select bonn;
    

    Or in extension method syntax:

    // start and end as before
    var query = loadedCustomData.Descendants("PrayerTime")
                    .Select(c => Bønn.FromXElement(c))
                    .Where(bonn => bonn.Dato >= start && bonn.Dato < end);
    
    0 讨论(0)
提交回复
热议问题