質問

Does anyone know if there is a setting that will stop you from deleting a collapsed section of code?

If I am deleting something I want to avoid accidentally deleting something I don't remember is there. Like if I am deleting 3-4 methods and one I don't want to delete is in the middle of them but is collapsed.

Maybe ReSharper or CodeRush have a tool?

役に立ちましたか?

解決

Preventing this sort of thing completely may be a non-trivial task.

A tool could certainly be created to do this, but there are many issues.

  • Which code to protect?
    • How to identify that code?
      • File, Procedure, Range?
  • What happens when the tool isn't loaded or fails to load?
  • What happens when someone else on your team doesn't use the tool and deletes the code anyway?

IMHO it may be more effective to develop practices and techniques

1. Detect that the code has been deleted.

2. Quickly Restore it.

Some potential ways to achieve this are:

Unit Tests

Write some simple unit tests that depend on, and of course test, the code which you are looking to protect. When these tests fail, you have deleted, or in some other way broken, your code.

VCS (Version Control System)

The simplest way to recover your code when you discover it has gone missing, would be through the use of a VCS (Version Control System). Personally I use git, but there are many other such VCS (and DVCS) on the market (free and commercial). I never have to worry about loosing code, because I trust git (and my backups) to keep it for me.

Tool \ Addin

If you want, you can create a CodeRush plugin pretty quickly.

This plugin could, for example, intercept the Del and Ctrl+X keys, check to see if there are any collapsed regions within the selection and eat (throw away) those keys, so that the operation is abandoned.

FWIW: I'm more than happy to help you in creating such an addon :)

Update: I have now created an addon and placed the code on github for anyone who wants a copy.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top