One of the great features of ReSharper in Visual Studio 2017 is that it will refactor my foreach loops into simple Linq expressions.
So it'll take:
foreach (var windForecastDataRecord in good)
{
var dbRec = new WindDayAheadHourForecast
{
SyncId = currentSyncJobId,
Site = windForecastDataRecord.SITE,
PredictionTimeEst = string.IsNullOrEmpty(windForecastDataRecord.PREDICTIONTIME)
? (DateTime?) null: DateTime.Parse(windForecastDataRecord.PREDICTIONTIME),
TimeEst = string.IsNullOrEmpty(windForecastDataRecord.TIME)
? (DateTime?)null : DateTime.Parse(windForecastDataRecord.TIME),
MegaWatts = decimal.Parse(windForecastDataRecord.MW),
MaxiumOutput = decimal.Parse(windForecastDataRecord.MAXIMUMOUTPUT),
Flags = windForecastDataRecord.FLAGS,
Grp = windForecastDataRecord.GROUP,
Region = windForecastDataRecord.REGION,
Zone = windForecastDataRecord.ZONE
};
dbRecords.Add(dbRec);
}
and make it:
var dbRecords = good.Select(windForecastDataRecord => new WindDayAheadHourForecast
{
SyncId = currentSyncJobId,
Site = windForecastDataRecord.SITE,
PredictionTimeEst = string.IsNullOrEmpty(windForecastDataRecord.PREDICTIONTIME)
? (DateTime?) null
: DateTime.Parse(windForecastDataRecord.PREDICTIONTIME),
TimeEst = string.IsNullOrEmpty(windForecastDataRecord.TIME)
? (DateTime?) null
: DateTime.Parse(windForecastDataRecord.TIME),
MegaWatts = decimal.Parse(windForecastDataRecord.MW),
MaxiumOutput = decimal.Parse(windForecastDataRecord.MAXIMUMOUTPUT),
Flags = windForecastDataRecord.FLAGS,
Grp = windForecastDataRecord.GROUP,
Region = windForecastDataRecord.REGION,
Zone = windForecastDataRecord.ZONE
})
.ToList();
BUT, my question is, when it comes time to debug or test that statement. is there a way that I can still step through each item in the collection one by one like the foreach could?
I honestly don't know how because it's like the runtime just does the work of building the collection when it's a Linq Expression. So I guess the real question is how do you debug Linq Expressions?