Quick-delete surrounding statements in Visual Studio or Resharper
06:31 02 Oct 2014

I often find I need to remove nesting statements, say an if conditional becomes irrelevant:

From

if (processFile != null && processFile.Exists)
{
    Process[] processesByName = GetProcesses(processFile.NameWithoutExt);
    if (processesByName.Length > 0)
    {
        return processesByName.ToList();
    }
}

return null;

To

Process[] processesByName = GetProcesses(processFile.NameWithoutExt);
if (processesByName.Length > 0)
{
    return processesByName.ToList();
}

return null;

The trouble is having to manually find the curly braces on both sides and delete them, while retaining the nested code

  • Especially with larger bodies, unlike the example here
  • Any way to quick-erase with Resharper?
  • Or in Visual Studio natively?
c# .net visual-studio visual-studio-2013 resharper