我正在检查我的解决方案,发现有几个类已被完全注释掉。我想把它们从我的解决方案中移除,并将更改提交到源代码控制中。我认为随着时间的推移,有人已经重构了这些代码或删除了它最初提供的任何功能。
我只是想知道是否还有其他类文件在我的项目中像这样,以便我可以清除垃圾。
我正在检查我的解决方案,发现有几个类已被完全注释掉。我想把它们从我的解决方案中移除,并将更改提交到源代码控制中。我认为随着时间的推移,有人已经重构了这些代码或删除了它最初提供的任何功能。
我只是想知道是否还有其他类文件在我的项目中像这样,以便我可以清除垃圾。
我不知道Visual Studio(非第三方)中是否有这样的工具,但您可以在整个项目中查找“//”,并手动选择大部分被注释的文件,否则编写一个扫描子目录中的所有文件并返回文件名的工具(Console App),如果文件中80%的行以“//”开头,则自动选择。
Public Sub AllFilesWhichAreEmptyOrCommentedOut()
Dim solution As Solution = DTE.Solution
For Each prj As Project In solution.Projects
For Each file As ProjectItem In prj.ProjectItems
If file.Name.EndsWith(".cs") OrElse file.Name.EndsWith(".vb") Then
file.Open()
Dim selection As EnvDTE.TextSelection = file.Document.Selection
If selection Is Nothing Then
Continue For
End If
selection.StartOfDocument()
selection.EndOfDocument(True)
Dim content As String = selection.Text
If content.StartsWith("/*") Then
Log("File " & file.Name & " starts with /*")
End If
If content.Length <= 1 Then
Log("File " & file.Name & " is empty.")
End If
' Reset selection back to top
selection.StartOfDocument()
End If
Next
Next
End Sub