I have 2 linq statements - currently located in the middle of the switch block. Statements below.
pwStartTime = lender.ApplicationWindows
.Where(w => w.Name == pwPeriod && w.EndTime.TimeOfDay > dateToCheck.TimeOfDay)
.Select(w => w.StartTime)
.FirstOrDefault();
pwStartTime = lender.TransferWindows
.Where(w => w.Name == pwPeriod && w.EndTime.TimeOfDay > dateToCheck.TimeOfDay)
.Select(w => w.StartTime)
.FirstOrDefault();
As you can see, the only difference is that they relate to two different properties of the “lender”, however, all the elements used in the linq query are identical in “ApplicationWindows” and “TransferWindows”, although they do not match objects and each of them contains other unique properties.
So, is it possible to return w.StartDate through one common method?
Thanks in advance.
// There are 2 classes
public class ApplicationWindow
{
public string Name { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
public class TransferWindow
{
public string Name { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
[XmlIgnore]
public TimeSpan Cycle { get; set; }
[Browsable(false)]
[XmlElement("Cycle")]
public string CycleString
{
get { return XmlConvert.ToString(Cycle); }
set { Cycle = value.IsNullOrEmpty() ? TimeSpan.Zero : XmlConvert.ToTimeSpan(value); }
}
}
source
share