Reminiscent of the title of a bootleg live Rolling Stones recording of yesteryear, Resharper is sharper than I'll ever be; as I had it inspect my code, it told me this regarding closures:
1) "Loop:
foreach (var item in PlatypiIds)
{
var query = db.Table<Locations>().Where(l => l.PlatypusId == item).
Where(l=> l.SentTimeUTC >= EarliestToShow).
Where(l=> l.SentTimeUTC <= LatestToShow).
OrderBy(l => l.SentTimeUTC);
if (query != null)
{
foreach (var q in query)
{
listLocs.Add(q);
}
}
}
...can be converted into LINQ expression:
listLocs.AddRange(from item in PlatypiIds select db.Table<Locations>().Where(l => l.PlatypusId == item).Where(l => l.SentTimeUTC >= EarliestToShow).Where(l => l.SentTimeUTC <= LatestToShow).OrderBy(l => l.SentTimeUTC) into query
where query != null from q in query select q);"
...but then Resharper told me later regarding the "new and improved" code: "Access to foreach variable in closure. May have different behaviour when compiled with different versions of compiler"
So what are the possibilities of compiling with a different version of the compiler? I mean, I'm not going to go backwards, version-wise, from VS2012 to VS2010, for example...???
2) On these lines:
if (db != null)
db.Insert(new PlatypiRequested()
...of this code:
using (var db = new SQLiteConnection(SQLitePath))
{
db.CreateTable<PlatypiRequested>();
db.RunInTransaction(() =>
{
if (db != null)
db.Insert(new PlatypiRequested()
{
PlatypusId = PlatypusId,
PlatypusName = PlatypusName,
InvitationSentLocal = invitationSentLocal
});
});
}
...Resharper informs me, "Access to disposed closure"
What does that mean, and what should I do about it?