如何在 Visual Studio 中反转等号周围的代码? [英] How can I reverse code around an equal sign in Visual Studio?

查看:37
本文介绍了如何在 Visual Studio 中反转等号周围的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写代码以从对象填充文本框后,例如:

After writing code to populate textboxes from an object, such as:

txtFirstName.Text = customer.FirstName;
txtLastName.Text = customer.LastName;
txtAddress.Text = customer.Address;
txtCity.Text = customer.City;

在 Visual Studio(或什至像 Resharper 之类的东西)中有没有办法将此代码复制并粘贴到保存函数中,并在等号周围反转代码,使其看起来像:

is there way in Visual Studio (or even something like Resharper) to copy and paste this code into a save function and reverse the code around the equal sign, so that it will look like:

customer.FirstName = txtFirstName.Text;
customer.LastName = txtLastName.Text;
customer.Address = txtAddress.Text;
customer.City = txtCity.Text;

推荐答案

VS2012 之前:

  • 复制并粘贴原始代码块
  • 在要切换的地方再次选择它
  • 按 Ctrl-H 以打开替换"框
  • 在查找内容"下输入:{[a-zA-Z.]*} = {[a-zA-Z.]*};
  • 在替换为"下放置:2 = 1;
  • 查看:选择"
  • 使用:正则表达式"
  • 点击全部替换

使用 .NET 正则表达式的 VS2012(大概是以后):

With VS2012 (and presumably later) which uses .NET regular expressions:

  • 复制并粘贴原始代码块
  • 在要切换的地方再次选择它
  • 按 Ctrl-H 以打开替换"框
  • 在查找内容"下输入:([a-zA-Z.]*) = ([a-zA-Z.]*);
  • 在替换为"下输入:${2} = ${1};
  • 确保选择了 .*(正则表达式)图标(替换文本框下方的第三个)
  • 点击全部替换
  • Copy and paste the original block of code
  • Select it again in the place you want to switch
  • Press Ctrl-H to get the "Replace" box up
  • Under "Find what" put: ([a-zA-Z.]*) = ([a-zA-Z.]*);
  • Under "Replace with" put: ${2} = ${1};
  • Make sure that the .* (regular expressions) icon is selected (the third one along under the replacement textbox)
  • Hit Replace All

这篇关于如何在 Visual Studio 中反转等号周围的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆