dfmmalaw
7/7/2017 - 7:13 PM

Use LINQ to check if item in list has specific value for one of its properties and the second way uses the "out" modifier to to return a va

Use LINQ to check if item in list has specific value for one of its properties and the second way uses the "out" modifier to to return a value with TryParse (which is a bool) and then change the value of the out paramater

IEnumerable<ReportParameter> reportParameterList = reportParameters as IList<ReportParameter> ?? reportParameters.ToList();
            
DateTime dateFrom;
DateTime dateTo;

string sDateFrom = reportParameterList.Where(i => i.Name == "DATE_FROM" && i.Values.Count == 1).Select(s => s.Values[0]).First();

if (!DateTime.TryParse(sDateFrom, out dateFrom))
{
    dateFrom = TimeService.Instance.now();
}

string sDateTo = reportParameterList.Where(i => i.Name == "DATE_TO" && i.Values.Count == 1).Select(s => s.Values[0]).First();

if (!DateTime.TryParse(sDateTo, out dateTo))
{
    dateTo = TimeService.Instance.now();
}