Share via


How to: Search for Objects, Definitions, and References (Symbols)

In the Object Browser, you can filter the names of symbols displayed in the Objects pane for the current browsing scope by selecting or entering a search string in the <Search> list on the Object Browser toolbar. Click Search to display all symbol names in the current browsing scope which include the search string. For example, a search on the string "MyObject" will return the names "MyObject," "MyObjectTest" and "CMyObject." Searches are not case-sensitive.

You can also search for symbols using the Find Symbol tab of the Find and Replace window, or the Find All References command on the Object Browser shortcut menus. These searches display their results in the Find Symbol Results window. For reference information on these windows, see Find Symbol, Find and Replace Window, and Find Symbol Results Window window. You can also search for definitions by clicking the Go To Definition command on the context menu in the code editor.

Searching for Symbols Using a Search String

The Search menu on the Object Browser toolbar uses the current browsing scope selected in the Browse menu. For more information on scoping searches, see How to: View and Alter the Browsing Scope.

To Search the current Browse scope using a Search string

  1. In the Search String field on the Object Browser toolbar, select a previous search string or enter all or part of a symbol name.

  2. Click Search.

    The Objects pane displays just those items within the Browse scope whose names include the Search String. The string is highlighted in each symbol name where it is matched.

To clear the results

  • Click the Clear Search button on the Object Browser toolbar.

    The Objects pane now displays all the objects in the current browsing scope.

Searching for Symbols Using Find Symbol

Use the Find Symbol tab of the Find and Replace window, or the Find All References command on the Object Browser shortcut menus, to locate lines in your project code where a symbol is defined, referenced, or used.

Find Symbol is useful for:

  • Searching for the definition of a symbol within your project, or discovering multiple definitions of a symbol.

  • Searching for references to a symbol, and instances where it is used within your code.

  • Exploring object hierarchies in referenced and external components, allowing you to learn about their functionality.

Find Symbol is different from finding text in that it:

  • Allows you to limit the search scope to include only symbols.

  • Indicates definitions and references to the symbol (when available) in the Find Symbol Results Window.

  • Allows you to search in external components for which you do not have the source code.

To display the Find Symbol tab

  1. On the Edit menu, expand Find and Replace.

  2. Choose Find Symbol.

    —or—

  3. If the Find and Replace window is already open, on the toolbar, click the triangular View button on left drop-down and then choose Find Symbol.

To find symbol names that match a search string

  1. Check out any files to be searched that are stored under source code control.

  2. Switch any documents open in Design view editors to Source view.

  3. Select Find and Replace from the Edit menu and choose Find Symbol.

    The Find and Replace window opens with the Find Symbol options displayed.

  4. In the Look in drop-down list, select a predefined search scope.

    • All Components - Searches all available components for the Find what string, including the current solution and its referenced components, the entire .NET Framework, and any components that you have added using Add Other Components.

    • .NET Framework - Searches the entire .NET Framework Class Library.

    • My Solution - Searches the symbol names already defined or referenced within the open solution.

    —or—

    Select one of the Custom Component Set search scopes.

    • Custom Component Set (Object Browser) - Searches the components currently added to the Custom Component Set search scope of the Object Browser.

    • Custom Component Set (Find Symbol) - Searches the components currently added to the Custom Component Set search scope Find Symbol.

    —or—

    Click the Browse (...) button to display the Edit Custom Component Set Dialog Box and select a custom set of search folders. For more information, see How to: View and Alter the Browsing Scope.

  5. Set Find options as needed. You can choose to match:

    • Whole word - When selected, the Find Symbol Result window only displays instances of the Find what string that are matched in complete words. For example, a search for "MyObject" will return "MyObject" but not "CMyObject" or "MyObjectC."

    • Prefix - When selected, the Find Symbol Results window displays any symbols whose names begin with the Find what string. For example, a search for "MyObject" will return "MyObject," "MyObjectTest," and so forth, but not "CMyObject."

    • Substring - When selected, the Find Symbol Results window displays all symbols whose names include the Find what string anywhere. For example, a search for "MyObject" will return "MyObject," "MyObjectTest" and "CMyObject."

    For any of these options, you can choose to:

    • Match case - When selected, the Find Symbol Results window only displays instances of the Find what string that are matched both by content and by case. For example, a search for "MyObject" with Match case selected will return "MyObject" but not "myobject" or "MYOBJECT."

    Note

    Find and Replace options are global, so they remain in effect from search to search. For more information, see Find Symbol, Find and Replace Window.

  6. In the Find what text box, enter the string or expression that you want to find. Note   Wildcards and regular expressions cannot be used in Find Symbol searches.

  7. Choose Find All to begin the search. To cancel a search in progress, choose Stop.

    The matches found are listed in the Find Symbol Results Window. To jump to a search match, double-click its entry.

The Go to Definition command on the code editor's context menu navigates you directly to the original definition for the selected code element. Alternatively, you can press the F12 key to invoke the Go to Definition command.

Go To Definition works with code elements such as members, types, variables, locals, and so forth. Go to Definition uses compiler information to navigate you directly to the original place where the code element is defined, even if your code heavily uses overloads or type inferences. The code where the element is defined must be available to Visual Studio, however, for Go To Definition to work correctly.

To navigate to a definition

  • Right-click a code element in the code editor and then click Go To Definition.

    The module where the code is originally defined, if it is available, displays in a new tab in the code editor. If the definition is not available, you will get the error message, "Cannot navigate to definition."

See Also

Tasks

How to: Navigate in the Object Browser

Reference

Find Symbol Results Window

Find Symbol Command

Code Definition Window