Page 22 - MSDN Magazine, November 2017
P. 22
Similarly, in the earlier example you can easily fix redundant internal modifiers for type definitions (internal is, in fact, the default modifier in C#). This technique applies to any analysis rule that highlights redundant code in the editor.
Navigating Code
Navigating between code files and between members in a code file is extremely common and having built-in, powerful naviga- tion tools significantly aids productivity. Visual Studio for Mac provides a number of robust tools that make it easier to navigate between files, types and members. First of all, you can quickly move between code files by pressing Control+Tab. This action shows a popup where you can see a list of files in your solution. Holding Control and pressing Tab again cycles down the list and then, when you release, the selected file will be opened in the editor. For source code navigation, the next subsections talk about less-known pro- ductivity features that are incredibly useful.
The Find All References and Navigate Tools
The Find All References tool allows you to retrieve all the ref- erences to a type or member in the solution. To see this tool in action, simply right-click a type or member name in the code editor and then select Find All References. References are shown in the Search Results pad, as shown in Figure 4.
In the Search Results pad, you can see (starting from left to right) the project that contains the reference, the code file
including the position, the source text that contained
the referenced object, and the full pathname of the
source file. You can double-click a reference and the code editor will open the appropriate code file and place the cursor on the selected occurrence. Notice how the source code in the Text column has basic syntax colorization. Find All References is very powerful, but sometimes you might want to filter your search based on certain type and member characteristics. To accomplish this, you can use the Navigate tool, which you invoke by right-clicking a type or member and then selecting Navigate. You’ll be presented with a submenu that shows the following search options:
Find References of All Overloads finds all ref- erences of a method and its overloads.
Base Symbols allows you to find the list of base types and interfaces that the type on which you invoked Navigate is inheriting from or is implementing. In the case of methods, Navigate will find the list of methods that the current method is overriding.
Derived Symbols allows you to find the list of types that inherit from the type on which you invoked Navigate. In the case of methods, it finds the list of methods that are overriding the one on which you invoked Navigate.
Extension Methods finds all the extension meth- ods for the type on which you invoked Navigate and that are defined in the current solution.
Member Overloads is similar to Extension Methods, but it finds the list of method overloads defined in the current solution. Implementing Members, if invoked on an abstract class or interface, shows the list of types and members that implement
that type or interface.
Visual Studio for Mac provides a number of robust tools that make it easier to navigate between files, types and members.
The Navigate tool shows the search results in the Search Results pad exactly like Find All References.
The Scrollbar and Minimap Mode
The code editor’s scrollbar displays colored markers that represent code issues, such as warnings and errors, breakpoints, ToDo items, and a colored dot at the top that’s red if the active file contains errors, yellow if the active file contains warnings, or green if no issues are
Figure 3 Removing Redundant Code
Figure 4 Finding a Type or Member References
18 msdn magazine
Visual Studio