在 Visual Studio IDE 中是否有交换/重新排序参数的快捷方式?

发布于 2024-09-10 19:16:53 字数 298 浏览 1 评论 0原文

在 IDE 中使用代码时,我遇到一个常见问题:

string.Concat("foo", "bar");

我需要将其更改为:

string.Concat("bar", "foo");

通常我有几个需要立即交换的代码。我想避免所有打字。有没有办法自动执行此操作?如果我知道从哪里开始,那么快捷方式或某种宏都会很棒。

编辑:更改为 string.Concat 以表明您不能总是修改方法签名。我只想更改方法调用中参数的顺序,而不是其他。

I have a common issue when working with code in the IDE:

string.Concat("foo", "bar");

and I need to change it to:

string.Concat("bar", "foo");

Often I have several of these that need to be swapped at once. I would like to avoid all the typing. Is there a way to automate this? Either a shortcut or some sort of macro would be great if I knew where to start.

Edit: changed to string.Concat to show that you can't always modify the method signature. I am only looking to change the order of the params in the method call, and nothing else.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娜些时光,永不杰束 2024-09-17 19:16:53

+ + 将调换两个单词,因此它适用于您的情况。不幸的是,对于具有较大参数列表的函数,我认为这不起作用(无需多次按下)...

<Ctrl> + <Shift> + <t> will transpose two words, so it would work in your case. Unfortunately I don't see this working (without multiple presses) for functions with larger parameter lists...

夜灵血窟げ 2024-09-17 19:16:53

我有很多带有这个函数的代码:

SetInt(comboBox1.Value + 1, "paramName", ...
SetInt(comboBoxOther.Value, "paramName", ...

而且我只需要交换前两个参数;

我最终使用了一些具有正则表达式管理功能的文本编辑器(例如 Scite),并使用了这个节省了我的时间:

Find: SetInt(\([.a-z0-9]+[ + 1]*\), \("[a-z0-9]+"\)
Replace: SetInt(\2, \1 

I had a lot of code with this function:

SetInt(comboBox1.Value + 1, "paramName", ...
SetInt(comboBoxOther.Value, "paramName", ...

And I needed to swap only the first two parameters;

I ended up using some text editor with regular expression management (like Scite), and using this one saved me hours:

Find: SetInt(\([.a-z0-9]+[ + 1]*\), \("[a-z0-9]+"\)
Replace: SetInt(\2, \1 
隔岸观火 2024-09-17 19:16:53

我使用的扩展程序恰好可以完成这一件事。

它描述自己为

允许参数(或包含在中的其他逗号分隔列表)
方括号、大括号等)左右移动。

https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.shifter

I use an extension that does exactly this one thing.

It describes itself as

Allows arguments (or other comma separated lists contained in
brackets, braces, etc.) to be shifted left and right.

https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.shifter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文