Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check if a variable is used in a project programmatically?

In VB.NET (or C#) how can I determine programmatically if a public variable in class helper.vb is used anywhere within a project?

like image 884
Kingamoon Avatar asked Sep 25 '08 23:09

Kingamoon


People also ask

How do you view variables in VS code?

Set a breakpoint in your code, and start debugging by pressing F5 or selecting Debug > Start Debugging. When paused at the breakpoint, hover over any variable in the current scope. A data tip appears, showing the name and current value of the variable.

How do I see variable values in Visual Studio debugging?

Hover over a variable to see its value. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

How do you check if a variable has been initialized C#?

Add a T Value and a bool IsInitialized property to it, and a constructor that takes a T parameter, assigns it to Value , and sets IsInitialized to true.


2 Answers

Find all References is your friend.

like image 140
Zee JollyRoger Avatar answered Sep 29 '22 17:09

Zee JollyRoger


From MSDN

The Find object allows you to search for and replace text in places of the environment that support such operations, such as the Code editor.

It is intended primarily for macro recording purposes. The editor's macro recording mechanism uses Find rather than TextSelection.FindPattern so that you can discover the global find functionality, and because it generally is more useful than using the TextSelection Object for such operations as Find-in-files.

If the search operation is asynchronous, such as Find All, then the FindDone Event occurs when the operation completes.

Sub ActionExample()
   Dim objFind As Find = objTextDoc.DTE.Find

   ' Set the find options.
   objFind.Action = vsFindAction.vsFindActionFindAll
   objFind.Backwards = False
   objFind.FilesOfType = "*.vb"
   objFind.FindWhat = "<Variable>"
   objFind.KeepModifiedDocumentsOpen = False
   objFind.MatchCase = True
   objFind.MatchInHiddenText = True
   objFind.MatchWholeWord = True
   objFind.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
   objFind.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
   objFind.SearchPath = "c:\<Your>\<Project>\<Path>"
   objFind.SearchSubfolders = False
   objFind.Target = vsFindTarget.vsFindTargetCurrentDocument
   ' Perform the Find operation.
   objFind.Execute()
End Sub



<System.ContextStaticAttribute()> _
Public WithEvents FindEvents As EnvDTE.FindEvents

Public Sub FindEvents_FindDone(ByVal Result As EnvDTE.vsFindResult, _
                               ByVal Cancelled As Boolean) _
                               Handles FindEvents.FindDone
   Select Case Result 
        case vsFindResultFound
             'Found!
        case else
             'Not Found
   Ens select
End Sub
like image 41
Nescio Avatar answered Sep 29 '22 16:09

Nescio