如何编写宏来添加 ; Visual Studio 中的每一行
我想构建一个宏,将 ;
添加到每个行尾,该行尾还没有且不为空,或者是 {
或 }.
我在 Visual Studio 2010 Professional 中使用 C#,因此我可能需要 VB 宏。
我需要它,因为我必须将 Unittest 从 VBS 迁移到 C#(不要问为什么)。所以我得到了数千行,比如 foo="53" bazz=1337
我不在乎支持是否被放弃,我应该在几周内完成。另外,如果有一个 ;
投入太多,我仍然会稍后查看代码。
I want to build a macro which adds a ;
to every line end, which hasn't already got one and is not empty or a {
or }
.
I use C# in Visual Studio 2010 Professional so I probably need a VB Macro.
I need it because I have to migrate Unittest from VBS to C# (Don't ask why). So I got thousands of lines like foo="53" bazz=1337
I do not care if support is dropped, I should be done in some weeks. Also if there is one ;
put in to much, i still review the code later.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道您要求使用宏,但搜索和替换正则表达式可以这样编写:
Visual Studio 有很好的选项可以“查看”当前文档、当前选择、所有打开的文档以及整个解决方案。 ..
I know you've asked for a Macro but a Search and Replace regular expression could be written something like this:
Visual Studio has good options for to "look in" the current document, current selection, all open documents, and the entire solution...
听起来您正在手动将单元测试代码从 VBS 重写为 C#,并希望自动添加分号。
我想说你应该编写一个脚本将 VB 代码转换为 C#;或者通过搜索和替换(如上面提到的正则表达式)来完成,然后将代码(或仅相关部分)复制到 C# 源代码中。
没有理由将其放入宏中。此外,像评论中提到的错误 -
for (int i = 0; i < 2; i++);
可能更难和/或更烦人地发现。Sounds like you are rewriting unittest code from VBS to C# by hand and want to add semicolons automatically.
I'd say you should rather write a script to convert the VB code to C#; or do it with a search-and-replace (like the regexes mentioned above), then copy the code (or only the relevant parts) into the C# source code.
There's no reason to make it into a macro. Furthemore, bugs like the one mentioned in comments -
for (int i = 0; i < 2; i++);
might be more difficult and/or annoying to find.