我想知道ReSharper是否可以运行每个类并删除未使用的使用?我看了,但我没有在R#4.5中看到这样的选项.有没有人在Resharper中看到这个只是能够删除单个类中的使用?
Kor*_*ius 92
从Resharper 9开始,您可以在清理使用块时选择"在解决方案中"范围.
bdu*_*kes 45
我相信整个项目的清理是ReSharper 5中的一项新功能.
我把它拿回去了,这个功能在ReSharper 4.5中.如果右键单击解决方案,则会有一个清理代码...项,它允许您将清理配置文件应用于解决方案.如果希望配置文件只调整using
指令,则可以从ReSharper选项中的"代码清理"节点创建新的清理配置文件.
还有另一种方式,我发现在这里,使用宏.
步骤1:通过Tools |在Visual Studio中创建一个新宏 宏菜单.
第2步:将下面的代码粘贴到模块中并保存
Public Module Module1
Sub OrganizeSolution()
Dim sol As Solution = DTE.Solution
For i As Integer = 1 To sol.Projects.Count
OrganizeProject(sol.Projects.Item(i))
Next
End Sub
Private Sub OrganizeProject(ByVal proj As Project)
For i As Integer = 1 To proj.ProjectItems.Count
OrganizeProjectItem(proj.ProjectItems.Item(i))
Next
End Sub
Private Sub OrganizeProjectItem(ByVal projectItem As ProjectItem)
Dim fileIsOpen As Boolean = False
If projectItem.Kind = Constants.vsProjectItemKindPhysicalFile Then
'If this is a c# file
If projectItem.Name.LastIndexOf(".cs") = projectItem.Name.Length - 3 Then
'Set flag to true if file is already open
fileIsOpen = projectItem.IsOpen
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
window.Activate()
projectItem.Document.DTE.ExecuteCommand("Edit.RemoveAndSort")
'Only close the file if it was not already open
If Not fileIsOpen Then
window.Close(vsSaveChanges.vsSaveChangesYes)
End If
End If
End If
'Be sure to apply RemoveAndSort on all of the ProjectItems.
If Not projectItem.ProjectItems Is Nothing Then
For i As Integer = 1 To projectItem.ProjectItems.Count
OrganizeProjectItem(projectItem.ProjectItems.Item(i))
Next
End If
'Apply RemoveAndSort on a SubProject if it exists.
If Not projectItem.SubProject Is Nothing Then
OrganizeProject(projectItem.SubProject)
End If
End Sub
End Module
Run Code Online (Sandbox Code Playgroud)
第3步:在你想要的任何解决方案上运行宏,你有它!请享用 :)
归档时间: |
|
查看次数: |
20304 次 |
最近记录: |