Reputation: 564
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?
Upvotes: 0
Views: 89
Reputation: 15701
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.
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.
Upvotes: 1