让人想起去年滚石乐队盗版现场录音的标题,Resharper 比我以往任何时候都更加敏锐;当我让它检查我的代码时,它告诉我有关闭包的信息:
1)“循环:
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);
}
}
}
...可以转换成 LINQ 表达式:
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);"
...但后来 Resharper 后来告诉我有关“新的和改进的”代码:“在闭包中访问 foreach 变量。使用不同版本的编译器编译时可能会有不同的行为”
那么使用不同版本的编译器进行编译的可能性有哪些呢?我的意思是,我不会从版本角度倒退,例如从 VS2012 到 VS2010...???
2)在这些方面:
if (db != null)
db.Insert(new PlatypiRequested()
...这段代码:
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 通知我,“访问已处理的关闭”
这是什么意思?我该怎么办?