visual studio-如何修复C#注释头
本文关键字:注释 何修复 studio- visual | 更新日期: 2023-09-27 17:58:22
使用自动注释头应用程序后,我发现它删除了代码启动前的最后一个返回。这意味着我在解决方案中的所有文件现在看起来都是这样的:
//-----------------------------------------------------------------------------
// File Name: Mapper.cs
// Creation Date: 13/02/2013
// Author: person
//-----------------------------------------------------------------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
我现在有几百个文件需要修复,但我的源代码控制消失了(在一台失效的EC2 Micro上)。我似乎在这里遇到了一系列不幸的事情。有没有一个宏或类似的东西可以帮助我摆脱这种束缚?
在Visual Studio中,您可以使用通配符进行全部替换,以便插入换行符。我现在没有可用的IDE,但它应该是这样的:
使用通配符在项目中的所有文件中搜索:
---using
替换为:
---'nusing
或者,正如Kirk建议的那样,使用正则表达式。
搜索:
---.*
替换为:
---'n'1
与使用IDE不同的方法是,您可以启动LinqPAD,然后运行以下代码(好吧,之前的备份是不要忘记的)
void Main()
{
string yourRootSolutionPath = @"D:'temp";
foreach(string s in Directory.EnumerateFiles(yourRootSolutionPath, "*.cs", SearchOption.AllDirectories))
{
string[] lines = File.ReadAllLines(s);
for(int x = 0; x < lines.Length; x++)
{
int pos = lines[x].IndexOf("---using");
if(pos > 0)
{
lines[x] = lines[x].Substring(0, pos+3) + Environment.NewLine + lines[x].Substring(pos+3);
File.WriteAllLines(s, lines);
break;
}
}
}
}
- 单击
Edit > Find and Replace > Find in Files
- 在"查找和替换"对话框中,展开
Find options
组框并启用Use Regular Expressions
- 在
Find what:
下拉粘贴-using System;
- 在
Replace with:
下拉粘贴-'rusing System;
- 在
Look in:
下拉列表中,使用Entire Solution
- 可选:您可以通过在
Look at these file types:
下拉列表中添加*.cs
来进一步限制搜索
尝试使用Find Next
和Replace
选项进行搜索。如果情况看起来不错,则向Visual Studio众神祈祷并单击Replace All
按钮。