Quickly delete external statements in Visual Studio or Resharper

I often find that I need to remove nesting instructions, say if the condition becomes inappropriate:

WITH

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

For

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

The problem is the need to manually find curly braces on both sides and delete them while maintaining the nested code

  • Especially with larger bodies, unlike the example here
  • Any way to quickly remove using Resharper?
  • Or in Visual Studio natively?
+6
source share
3 answers

Shidt+delete cut the IF line

Alt+Enter on the bracket to remove the extra curly braces.

+8
source

Change the condition to if (true || whatever) ? I think ReSharper will tell you that the condition is always true and will suggest deleting it.

+2
source

One solution, although it may not be ideal:

  • Click and drag to mark the code you want to save.
  • Use the Resharper "Surround with ..." command and select " #region ".
  • Now you can collapse the code you want to save using the minus sign at the top of the new region.
  • Remove the code surrounding #region
  • Now click on the #region heading again and select the Resharper option "Remove region / endregion directives".

Not an ideal solution, but it should help you get a better overview of what you are doing while working with larger blocks of code than your OP example.

It should look something like this (where the #region directive can hide any lines of code):

enter image description here

+1
source

Source: https://habr.com/ru/post/976145/


All Articles