我怎样才能扭转码左右在Visual Studio等号? [英] How can I reverse code around an equal sign in Visual Studio?

查看:189
本文介绍了我怎样才能扭转码左右在Visual Studio等号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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



有没有在Visual Studio的方式(甚至像ReSharper的)这段代码复制并粘贴到一个保存功能和反向等号周围的代码,因此,它看起来像:

  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(可能更高):




  • 复制并粘贴代码原始块

  • 又在这个地方选择它要切换

  • 按Ctrl-H获得替换为框中高达

  • 在查找内容提出:([A -za-Z\] *)=(A-ZA-Z\] *);

  • 在替换为放。: $ {2} = $ {1};

  • 确保该 * 被选中(正则表达式)图标(更换文本框下沿第三个)

  • 点击全部替换


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;

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;

解决方案

Before VS2012:

  • 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;
  • Look in: "Selection"
  • Use: "Regular expressions"
  • Hit Replace All

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

  • 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天全站免登陆