Access to modified closure redux
Ignoring the utter vacuousness of this code - 'pstname' at the end of the second line warrants a "Access to modified closure".
var pstname = fullpath + "\\" + rootname + "\\" + "NFC" + rootname.StripLastCharsOf(".");
if (!Directory.Exists(Path.GetDirectoryName(pstname)) && !Execute.TryBool(() => Directory.CreateDirectory(Path.GetDirectoryName(pstname))))
{
_errorReport.AppendLine(fullpath + "\\" + rootname + "," + "Export" + "," + "Cant Create Directory");
continue;
}
=====================================================================================================
Allowing resharper to fix it generates the code below. Now I could be a little slow and dense, but I'm not really getting the distinction and of course
it starts squawking about changing 'string' to 'var' (why didn't it just do it?). Could someone either explain the distinction or fix this, as it's pretty irritating.
var pstname = fullpath + "\\" + rootname + "\\" + "NFC" + rootname.StripLastCharsOf(".");
string pstname1 = pstname;
if (!Directory.Exists(Path.GetDirectoryName(pstname)) && !Execute.TryBool(() => Directory.CreateDirectory(Path.GetDirectoryName(pstname1))))
{
_errorReport.AppendLine(fullpath + "\\" + rootname + "," + "Export" + "," + "Cant Create Directory");
continue;
}
string pstname1 = pstname;
if (!Directory.Exists(Path.GetDirectoryName(pstname)) && !Execute.TryBool(() => Directory.CreateDirectory(Path.GetDirectoryName(pstname1))))
{
_errorReport.AppendLine(fullpath + "\\" + rootname + "," + "Export" + "," + "Cant Create Directory");
continue;
}
Please sign in to leave a comment.
Hello,
This behavior should be fixed in the upcoming ReSharper 6 and it will not
report 'Access to modified closure' in this case. Thank you!
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"