Navigating in depth

Solution Explorer in VS2015 provides a range of features intended to make navigating and searching within your solution effective without overcomplication. Knowing how to efficiently move among solution files will only help your productivity, so let's take a look at what is available.

Getting ready

Open the same web application solution that we have been using for the other recipes in this chapter, or choose a solution of your own. The concepts here will be of use in any project type.

How to do it...

  1. We'll begin by navigating through our solution. Locate the Global.asax file in the web app solution, and click on the arrow next to it so that its contents are displayed. As you would expect, there is a code-behind file:
    How to do it...
  2. Look at the Global.asax.cs file. You can see that there is a small arrow next to it, just as there was for the Global.asax page. Click on the arrow:
    How to do it...
  3. VS2015 expands the file to show its contents, and in the case of a code-behind file, these contents are the class definitions it contains. Classes have methods and properties in them, so click on the arrow next to the MvcApplication class to see the methods inside it. In this case, there is a method called Application_Start(), as shown in the following screenshot:
    How to do it...
  4. Now select the AccountController.cs file from the project, and expand it to see its contents. You will see that there is a class definition (AccountController), as shown in the following screenshot:
    How to do it...
  5. Right-click on the AccountController class, and click on the Base Types option to see what class this is based on:
    How to do it...
  6. The Solution Explorer window will change views to show you the classes that AccountController is derived from, as shown in the following screenshot (with class hierarchy fully expanded). Click on the back button (as marked by the arrow) to return to the standard Solution Explorer view:
    How to do it...
  7. Right-click on the AccountController class, and choose the Is Used By option to see where the interface is currently being used. As with the Base Types or Derived Types options, you will see Solution Explorer change its context to only show the interface and where that interface is used in the solution, including line and column numbers:
    How to do it...
  8. Return to the regular Solution Explorer view by clicking on the home button:
    How to do it...
  9. At this point, you know how to navigate using Solution Explorer, and you have already used the existing Navigate To feature in the Finding Visual Studio commands recipe while opening a file. With the enhancements to Solution Explorer, you can locate files in much the same way as with the Navigate To command, albeit with a slightly different user experience. Click on the Search Solution Explorer textbox at the top of the Solution Explorer window, or use the default shortcut key: Ctrl + ; (Ctrl + semicolon).
  10. Enter models in the textbox, and wait a moment for the search results to display. The results should look similar to the following screenshot if you are using the sample project. You can see, not only the filenames that match the search term, but also any matching references, classes, and methods:
    How to do it...

How it works…

The Solution Explorer search tool provides similar results to the Navigate To feature, but having the location of a match represented in the tree view makes it very easy to quickly identify the specific match you are interested in.

There's more...

It's worth mentioning a few other things about searching within your solution.

Navigation behavior

Assuming you have the Preview icon enabled for Solution Explorer, as you navigate using Solution Explorer to various classes and methods, you may have noticed that the document preview tab updates and shows exactly where the selected class, method, or property was declared. This makes it easy to see what the code is doing without the need to specifically open the file, or scroll through a source file to see the code which is actually inside a method, class, or property. The Preview icon's location in the Solution Explorer window is shown in the following screenshot:

Navigation behavior

CSS, HTML, and JavaScript files

Even though it's possible to extract the structure from CSS, HTML, and JavaScript files, Solution Explorer doesn't show the internal structure of these files. You can navigate to the source file, but not to any of its contents.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.1.239