2010-02-25 17 views
44

Tôi tự hỏi liệu có lẽ ReSharper có thể chạy qua mọi lớp và loại bỏ các ứng dụng không sử dụng? Tôi nhìn nhưng tôi không thấy một tùy chọn như thế này trong R # 4.5. Có ai nhìn thấy điều này trong Resharper bên ngoài chỉ có thể loại bỏ việc sử dụng trong một lớp học duy nhất?Xóa các Sử dụng không được sử dụng trên toàn bộ assembly

Trả lời

38

Tôi tin rằng dọn dẹp qua một dự án là một tính năng mới trong ReSharper 5.

tôi lấy lại đó, tính năng này trong ReSharper 4.5. Nếu bạn nhấp chuột phải vào giải pháp, có Mã Dọn dẹp ... mục, cho phép bạn áp dụng hồ sơ dọn dẹp cho giải pháp. Bạn có thể tạo một hồ sơ dọn dẹp mới từ nút Code Cleanup trong các tùy chọn ReSharper, nếu bạn muốn một hồ sơ chỉ cần điều chỉnh các chỉ thị using.

4

Ngoài ra còn có another way I found here, sử dụng Macro.

Bước 1: Tạo macro mới trong Visual Studio thông qua Công cụ | Macro menu.

Bước 2: Dán mã dưới đây vào Module và lưu nó

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 

Bước 3: Chạy vĩ mô trên bất kỳ giải pháp mà bạn muốn và bạn đã có nó! Thưởng thức :)

65

Vì Resharper 9, bạn chỉ có thể chọn phạm vi "trong giải pháp" khi bạn dọn sạch khối sử dụng.

enter image description here

+0

Chắc chắn là tùy chọn đơn giản nhất. – Zapnologica

Các vấn đề liên quan