官术网_书友最值得收藏!

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:
  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:
  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:
  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:
  5. Right-click on the AccountController class, and click on the Base Types option to see what class this is based on:
  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:
  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:
  8. Return to the regular Solution Explorer view by clicking on the home button:
  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 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:

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.

主站蜘蛛池模板: 梁河县| 远安县| 漠河县| 岐山县| 二手房| 翁源县| 平顶山市| 孝义市| 新源县| 隆德县| 华容县| 荣昌县| 清镇市| 西城区| 越西县| 潜山县| 元阳县| 元谋县| 盐池县| 平塘县| 丰宁| 广德县| 龙海市| 马龙县| 台江县| 江阴市| 略阳县| 绥芬河市| 波密县| 宿迁市| 濮阳市| 庆阳市| 曲沃县| 大荔县| 瓮安县| 尼玛县| 徐闻县| 平昌县| 微山县| 菏泽市| 淄博市|