【发布时间】:2015-04-20 17:37:25
【问题描述】:
我不得不通过一个包含不可用项目的大型解决方案。这些不可用的项目不可用,因为它们的路径不再存在。如果此解决方案要保留这些不可用的引用,是否有办法确定我正在循环的每个项目是否可用/不可用?
下面是一个循环,其目标是确定是否保存了当前解决方案中的每个 ProjectItem。但是,由于某些项目不可用,我不断收到空引用。
bool isDirty = false;
foreach (Project proj in sln.Projects) //sln is my current solution
{
if (proj == null) //hoping that might do the trick
continue;
foreach (ProjectItem pi in proj.ProjectItems)
{
if (pi == null) //hoping that might do the trick
continue;
if (!pi.Saved)
{
isDirty = true;
break;
}
}
}
【问题讨论】: