在foreach中检测到无法访问的代码

本文关键字:访问 代码 foreach 检测 | 更新日期: 2023-09-27 18:20:08

我在vs2012中收到了这个警告,但无法找出无法访问的代码在哪里

private void LoadGridData()
{
    string currentUrl = SPContext.Current.Site.Url;
    var jobInfoList = new List<JobInfo>();
    SPSecurity.RunWithElevatedPrivileges(delegate
        {
            using (var clientSiteCollection = new SPSite(currentUrl))
            {
                foreach (
                    SPWeb web in
                        clientSiteCollection.AllWebs.Where(
                            c =>
                            c.AllProperties[Constants.WebProperties.General.WebTemplate] != null &&
                            c.AllProperties[Constants.WebProperties.General.WebTemplate].ToString() ==
                            Constants.WebTemplates.JobWebPropertyName).OrderByDescending(d => d.Created).Take(5)
                    )
                {
                    SPList jobInfoListSp = web.Lists.TryGetList(Constants.Lists.JobInfoName);
                    if (jobInfoListSp != null)
                    {
                        if (jobInfoListSp.Items.Count > 0)
                        {
                            var value =
                                new SPFieldUrlValue(
                                    jobInfoListSp.Items[0][Constants.FieldNames.Job.Link].ToString());
                            jobInfoList.Add(new JobInfo
                                {
                                    JobName =
                                        jobInfoListSp.Items[0][Constants.FieldNames.Job.JobName].ToString(),
                                    JobCode =
                                        jobInfoListSp.Items[0][Constants.FieldNames.Job.JobCode].ToString(),
                                   Link = value.Url,
                                    JobWebsite = web.Url,
                                    IsConfidential =
                                        Convert.ToBoolean(
                                            jobInfoListSp.Items[0][Constants.FieldNames.Job.Confidential])
                                });
                        }
                    }
                    web.Dispose();
                }
            }
        });
    _lastCreatedJobsGrid.DataSource = jobInfoList;
    _lastCreatedJobsGrid.DataBind();
}

在foreach中检测到无法访问的代码

愚蠢的回答哈哈,其中一个常量被移动了位置,然后该类不再编译,但是警告已经存在,一旦我修复了常量引用,那么警告就消失了。