For quite some time now (I should say many years), I had a very simple task on my TODO list (mine is particularly long!).
This little task was simply: In Visual Studio, how to search for a word which is not on a commented line?
That would have been nice if the VS IDE would offer that option built-in, but it is sadly not! Another useful option would be to colorize the search results exactly like the code window does.
This morning, I was working in a new project for a new client and find they are not deleting lines of code very often, they are most of the time commenting out the code (even if the code hosted in TFS). I was searching for a word and the Find in files feature (CTRL-SHIFT-F) returned literally many hundreds of rows, most of them being commented out. It was nearly impossible to find out the line of codes (about 20) in this non-ending results.
I opened a browser and quickly found an old solution on stack overflow that is working great. The trick is to use a regular expression in the “Find what” textbox and to check the “Use Regular Expressions” under “Find options”. The very same trick also works for the regular search feature (CTRL-F).
The other nice thing about this trick is that using the same idea (with slight difference in syntax), it works in VB.Net, C#, and even in SSMS.
The regular expression to use are (depending on language and/or IDE):
VB.Net^(?![ \t]*').*YourSearchTermC#^(?![ \t]*//).* YourSearchTermSQL^(?![ \t]*--).*YourSearchTerm
I know, there are more ways to comment out code (like /* … */) for which this trick won’t work. But at least for today since I don’t have that kind in the code I am looking at, I will stop there. If you find a better solution, let me know!
Nice finding over the weekend.
I did not try it (as I use a 3rd party component) but one that might be worth testing in the feature: https://discoverdot.net/projects/ribbon-winforms
One cross-platform .NET library for IMAP, POP3, and SMTP which I will definitely try in the future: http://www.mimekit.net/#. This library is open source and under MIT License (free for personal and commercial use).