开发者

Method to remove specific obsolete lines of code from an entire codebase?

I have some code:

#if SILOG
    SiAu开发者_如何学Cto.Main.LogException(ex);
    // some other lines
#endif

What would be the easiest way to remove surrounding #if from my entire codebase, i.e., end up with just:

SiAuto.Main.LogException(ex);

I'm using Visual Studio 2010. I'll accept the first answer that I can test to see if it works. Looking forward to your ideas!


Assuming your codebase is all in one solution file, and you don't have nested preprocessor directives, You can do a find and replace with a regexp:

\#if SILOG{(.*\n)@}\#endif

For the replacement string, use this:

\1

Make sure have are using the "Regular expressions" find option checked.

Step by step:

  1. Open the find and replace dialog (ctrl+H)
  2. Under "Find what:", enter "#if SILOG{(.*\n)@}#endif" without the quotes
  3. Under "Replace with:", enter "\1" without the quotes
  4. Under "Look in", select "Entire Solution"
  5. Expand "Find options"
  6. Check "Use:" and select "Regular expressions" from the combobox
  7. Click "Find Next" to see if it worked
  8. Click "Replace All" if you're brave

This won't fix the indentation of the code that was between the #if / #endif, however.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜