VS.NET 查找未使用过的方法
2010-01-12 16:17
573 查看
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module SearchALlReference
Sub SearchAllDocuments()
For Each doc As Document In DTE.Documents
If doc.Name.EndsWith(".cs") Then
SearchAllFunctionReference(doc)
End If
Next
End Sub
Sub SearchAllFunctionReference(byval doc As Document)
Dim textSelection As EnvDTE.TextSelection
Dim codeElement As EnvDTE.CodeElement
Dim codeElements As EnvDTE.CodeElements
Dim classElement As EnvDTE.CodeElement
Dim codeModel As EnvDTE.FileCodeModel = doc.ProjectItem.FileCodeModel
Dim i, j, k As Integer
For i = 1 To codeModel.CodeElements.Count
codeElement = codeModel.CodeElements.Item(i)
If codeElement.Kind = vsCMElement.vsCMElementNamespace Then
'クラスを取得
Dim classElements = codeElement.Children()
For j = 1 To codeElement.Children().Count
If codeElement.Children().Item(j).Kind = vsCMElement.vsCMElementClass Then
classElement = codeElement.Children().Item(j)
For k = 1 To classElement.Children.Count
If classElement.Children().Item(k).Kind = vsCMElement.vsCMElementFunction Then
'参照の検索
Dim cnt As Integer
cnt = SearchReference(classElement.Children().Item(k), doc)
'If cnt <= 1 Then MsgBox(classElement.Children().Item(k).Name)
If cnt <= 1 Then ShowNotRefenceToOutputWindow(classElement.Name & " : " & classElement.Children().Item(k).Name & Environment.NewLine)
End If
Next
End If
Next
End If
Next
End Sub
Function ShowNotRefenceToOutputWindow(ByVal content As String)
Dim outputWindowPane As OutputWindowPane
outputWindowPane = GetOutputWindowPane("出力")
outputWindowPane.Clear()
outputWindowPane.OutputString(content)
End Function
Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane
Dim window As Window
Dim outputWindow As OutputWindow
Dim outputWindowPane As OutputWindowPane
window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
If show Then window.Visible = True
outputWindow = window.Object
Try
outputWindowPane = outputWindow.OutputWindowPanes.Item(Name)
Catch e As System.Exception
outputWindowPane = outputWindow.OutputWindowPanes.Add(Name)
End Try
outputWindowPane.Activate()
Return outputWindowPane
End Function
Function SearchReference(ByVal codeElement As EnvDTE.CodeElement, ByVal doc As Document) As Integer
Dim textSelection As EnvDTE.TextSelection
Dim resultcount As Integer
Dim rescaption As String
Dim regex As New System.Text.RegularExpressions.Regex(" - [0-9]+")
textSelection = doc.Selection
Try
If Not (codeElement Is Nothing) Then
textSelection.MoveToPoint(codeElement.GetStartPoint(vsCMPart.vsCMPartHeader))
'エレメント名選択
textSelection.FindText(codeElement.Name, vsFindOptions.vsFindOptionsMatchCase)
'すべての参照の検索を実行
doc.Activate()
DTE.ExecuteCommand("Edit.FindAllReferences")
rescaption = DTE.Windows.Item(Constants.vsWindowKindFindSymbolResults).Caption
'検索結果ウィンドウのタイトルから件数を取得
resultcount = CType(regex.Match(rescaption).Value.Substring(3), Integer)
Return resultcount
End If
Catch ex As Exception
End Try
End Function
End Module
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module SearchALlReference
Sub SearchAllDocuments()
For Each doc As Document In DTE.Documents
If doc.Name.EndsWith(".cs") Then
SearchAllFunctionReference(doc)
End If
Next
End Sub
Sub SearchAllFunctionReference(byval doc As Document)
Dim textSelection As EnvDTE.TextSelection
Dim codeElement As EnvDTE.CodeElement
Dim codeElements As EnvDTE.CodeElements
Dim classElement As EnvDTE.CodeElement
Dim codeModel As EnvDTE.FileCodeModel = doc.ProjectItem.FileCodeModel
Dim i, j, k As Integer
For i = 1 To codeModel.CodeElements.Count
codeElement = codeModel.CodeElements.Item(i)
If codeElement.Kind = vsCMElement.vsCMElementNamespace Then
'クラスを取得
Dim classElements = codeElement.Children()
For j = 1 To codeElement.Children().Count
If codeElement.Children().Item(j).Kind = vsCMElement.vsCMElementClass Then
classElement = codeElement.Children().Item(j)
For k = 1 To classElement.Children.Count
If classElement.Children().Item(k).Kind = vsCMElement.vsCMElementFunction Then
'参照の検索
Dim cnt As Integer
cnt = SearchReference(classElement.Children().Item(k), doc)
'If cnt <= 1 Then MsgBox(classElement.Children().Item(k).Name)
If cnt <= 1 Then ShowNotRefenceToOutputWindow(classElement.Name & " : " & classElement.Children().Item(k).Name & Environment.NewLine)
End If
Next
End If
Next
End If
Next
End Sub
Function ShowNotRefenceToOutputWindow(ByVal content As String)
Dim outputWindowPane As OutputWindowPane
outputWindowPane = GetOutputWindowPane("出力")
outputWindowPane.Clear()
outputWindowPane.OutputString(content)
End Function
Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane
Dim window As Window
Dim outputWindow As OutputWindow
Dim outputWindowPane As OutputWindowPane
window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
If show Then window.Visible = True
outputWindow = window.Object
Try
outputWindowPane = outputWindow.OutputWindowPanes.Item(Name)
Catch e As System.Exception
outputWindowPane = outputWindow.OutputWindowPanes.Add(Name)
End Try
outputWindowPane.Activate()
Return outputWindowPane
End Function
Function SearchReference(ByVal codeElement As EnvDTE.CodeElement, ByVal doc As Document) As Integer
Dim textSelection As EnvDTE.TextSelection
Dim resultcount As Integer
Dim rescaption As String
Dim regex As New System.Text.RegularExpressions.Regex(" - [0-9]+")
textSelection = doc.Selection
Try
If Not (codeElement Is Nothing) Then
textSelection.MoveToPoint(codeElement.GetStartPoint(vsCMPart.vsCMPartHeader))
'エレメント名選択
textSelection.FindText(codeElement.Name, vsFindOptions.vsFindOptionsMatchCase)
'すべての参照の検索を実行
doc.Activate()
DTE.ExecuteCommand("Edit.FindAllReferences")
rescaption = DTE.Windows.Item(Constants.vsWindowKindFindSymbolResults).Caption
'検索結果ウィンドウのタイトルから件数を取得
resultcount = CType(regex.Match(rescaption).Value.Substring(3), Integer)
Return resultcount
End If
Catch ex As Exception
End Try
End Function
End Module
相关文章推荐
- VS.net IDE中,使用正则表达式进行查找、替换
- .net datatable 查找一行时的方法比较datatable.rows.find vs datable.select vs dataview vs for loop
- 在vs.net 2010中使用重构方法
- vs.net console 使用 web.config 连接数据库的方法
- vs.net git版本仓库使用 之解决冲突方法 原创
- 如何使用vs.net生成方法的小技巧
- 如何使用vs.net生成方法的小技巧
- VS 2005 (.Net 2.0) 提供的Login1的使用方法
- VS.net 中,使用正则表达式进行查找、替换
- 安装完vs.2005之后,重新安装iis后无法使用http方式访问asp.net工程的页面的问题的解决方法
- 使用vs的性能分析asp.net程序时报错的解决方法
- 使用vs的性能分析asp.net程序时报错的解决方法 (转载)
- VS 2005使用map文件查找程序崩溃原因
- ASP.NET使用EF时的seed方法以及初始数据的构造
- 如何使用VS.NET调试数据库存储过程 (转)
- 在vs里面安装ODP.NET连接oracle数据库,及代码如何使用
- html dom中要查找希望操作的元素使用的方法:getElementById()和getElementsByTagName()的区别
- 总结:ADO.NET在开发中的部分使用方法和技巧
- ASP.NET中String.IndexOf 方法的使用
- vb.net datagridview 使用方法