C#项目中的批量重命名(重构) [英] Mass renaming (refactoring) in C# project

查看:37
本文介绍了C#项目中的批量重命名(重构)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我收到了一个包含两列的 Excel 文件.我必须根据 excel 文件重命名解决方案中的对象.

Today, I received an excel file with two columns. I have to rename objects in a solution according to excel file.

第一列包含当前名称",第二列包含新名称".那里有 5000 多行.

First column contains "current name", second column contains "new name". More than 5000 lines there.

目前是 VS2013 with Resharper,C# 解决方案包含多个项目.

Currently it is VS2013 with Resharper, C# solution contains several projects.

如何自动执行此过程?

推荐答案

不幸的是,最近版本的 Visual Studio 丢失了宏(本质上:没有足够的人使用它们).因此,最简单的路径不可用.

Unfortunately recent versions of Visual Studio have lost macros (essentially: not enough people using them). Thus the easiest path is unavailable.

正如另一个 answer 注释(现已删除),使用现有 VS 工具一次执行一个名称是可能的,但对于 5000 显然不可行!

As the other answer notes (now deleted), doing this one name at a time with existing VS tools is possible, but clearly infeasible for 5000!

我会通过以下方式解决这个问题:

I would approach this by:

  1. 寻找其他工具,即使它们有价格,节省的时间也可能很重要.如果没有找到,请尝试 #2.几个月后 Rosalyn 可能是一个选择(或者甚至是它的预览:我认为你不会将它与客户一起投入生产!).

  1. Look for other tools, even if they have a price the time saved is likely to be significant. If nothing found, try #2. Given a few months Rosalyn might be an option (or even a preview of it: you won't be putting this into production with customers I assume!).

在脚本工具(例如 PowerShell:访问完整 .NET 框架和内置 CSV 支持的优势)中进行简单的搜索和替换以执行一次替换(您需要决定包括或排除注释和字符串).然后对每次重命名重复此操作.

Put together a simple search and replace in a script tool (eg. PowerShell: advantage of having access to the full .NET framework and inbuilt CSV support) to perform one substitution (and you'll need to decide to include or exclude comments and strings). Then repeat that for each renaming.

#2 可能需要几次尝试:误报太容易了.

#2 is likely to need to few tries: false positives will be all too easy.

这篇关于C#项目中的批量重命名(重构)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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