这有效:
public override bool GetAppointments(CalendarModel calendar, DateTime startDate, DateTime endDate) {
foreach (var googcal in _settings.Calendars.Where(googcal => googcal.Selected)) {
var eventQuery = new EventQuery {
Uri = new Uri(googcal.ProviderData),
// Passed in startDate/endDate are inclusive
StartTime = startDate.Date,
EndTime = endDate.Date.AddDays(1).AddMilliseconds(-1)
};
var eventFeed = Service.Query(eventQuery);
foreach (EventEntry appt in eventFeed.Entries) {
...
}
}
return true;
}
这不会:
public override bool GetAppointments(CalendarModel calendar, DateTime startDate, DateTime endDate) {
foreach (var googcal in _settings.Calendars.Where(googcal => googcal.Selected)) {
var eventQuery = new EventQuery {
// Passed in startDate/endDate are inclusive
StartTime = startDate.Date,
EndTime = endDate.Date.AddDays(1).AddMilliseconds(-1),
Uri = new Uri(googcal.ProviderData)
};
var eventFeed = Service.Query(eventQuery);
foreach (EventEntry appt in eventFeed.Entries) {
...
}
}
return true;
}
在第一种情况下Event.Query.StartTime
,EndTime
按预期正确设置。
在第二种情况下,它们是未初始化的 ( 1/1/0001 12:00:00 AM
)。
唯一的区别是对象初始值设定项中属性的顺序。
为了咧嘴笑,我做了这样的命令:
// Passed in startDate/endDate are inclusive
StartTime = startDate.Date,
Uri = new Uri(googcal.ProviderData),
EndTime = endDate.Date.AddDays(1).AddMilliseconds(-1)
果然EndTime
是正确的,但未StartTime
初始化。
这对我来说毫无意义。怎么会这样?