stupid answer lol , one of the constants was moved of place, then the class was not compiling anymore, however the warning was there, Once I fixed the constant reference then the warning is gone.
unreachable code detected in a foreach
-
01-06-2022 - |
Domanda
I have got this warning in vs2012 but can't figure out where is the unreachable code.
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();
}
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow