Hidden Gems in Visual Studio 2. Ive been working on developer tooling for over 1. I still love it when I find a new tip or trick that shaves seconds off a repetitive task. The set below are features that I see infrequently used but can save loads of time Gem 1 Expression Evaluator Format Specifiers. The part of the debugger that processes the language being debugged is known as the expression evaluator EE. A different expression evaluator is used for each language, though a default is selected if the language cannot be determined. The expression evaluators have some lesser known features, and though they arent always standardized across languages, they come in handy now and then. A format specifier, in the debugger, is a special syntax to tell the EE how to interpret the expression being examined. There are many format specifiers that are understood by the C EE, and a smaller set understood by the C and VB EEs. As an example, imagine that you want to call a method every time you step to see what the updated value is. Youre probably used to seeing this and having to click on the refresh icon However, you can use the ac always calculate format specifier to force evaluation on every step. I also find the h hexadecimal format specifier useful. You can leave the global display of the debugger alone, but update a single watch item to report in hex by using value,h. Drum Sounds Wav Music Files here. You can read about all of the different format specifiers for both C and CVB. BIA, The Business Intelligence and Analytics Conference formerly known as SABOC, is a celebration of the people, technology, ideas, and innovations that are. Visual Studio Customer Experience Improvement Program: Full Version Software' title='Visual Studio Customer Experience Improvement Program: Full Version Software' />Gem 2 Controlling the value column of the debugger. The measure of a modern debugger is its ability to display runtime object data in a simple and meaningful way. As such, when the debugger displays this information, it needs to show the most interesting values prominently. Unfortunately, it is difficult for the debugger to analyze arbitrary objects and figure out what is most important. The only generic solution is for you to control what the debugger displays which leads us quite nicely into attributed debugging. Attributed debugging gives the author of the type the ability to specify what it looks like when being debugged. Visual Studio Customer Experience Improvement Program: Full Version Software' title='Visual Studio Customer Experience Improvement Program: Full Version Software' />Visual Studio Customer Experience Improvement Program: Full Version SoftwareVisual Studio Customer Experience Improvement Program: Full Version SoftwareDownload the latest from Windows, Windows Apps, Office, Xbox, Skype, Windows 10, Lumia phone, Edge Internet Explorer, Dev Tools more. The simplest form of this is the Debugger. Display. Attribute. Imagine debugging the following code class Person. First. Name. public string Last. Name. public Personstring first, string last. First. Name first. Last. Name last. Full. Name get Last. Name, First. Name. Mainstring args. Listlt Person presidents new. Listlt Person. PersonGeorge, Washington. PersonJohn, Adams. PersonThomas, Jefferson. PersonJames, Madison. PersonJames, Monroe. If you set a breakpoint on the closing brace of Main, and examine presidents, youll see something like this If you want to examine the properties of James Madison, then you must know that he was the 4th president. You could override To. String in Person the EE will call To. String if its overridden. However, that causes a function evaluation, which can be hundreds of times slower than normal data inspection, and it may be that the debug view of the data should be different than the To. String view. For those cases you can use Debugger. Display as follows Debugger. DisplayName Full. Name,nq. This updates the display, to the more scannable You can include format specifiers in the expression to evaluate. In this case nq means no quotes when displaying the string. Gem 3 Showing important values when an object is expanded. We now have an easier time finding James Madison without expanding every node however, after we expand, we see the following view This shows a lot of duplicative information, and in this case, we dont really need it. Not only that, but it consumes 3 full rows of the watch window, where vertical space is precious. Since we know how Full. Name is calculated were comfortable never seeing First. Name or Last. Name when a Person is expanded. This is achieved through the Debugger. Browsable. Attribute. For example, if we add the following attributes Debugger. BrowsableDebugger. Browsable. State. Never. public string First. Name. Debugger. BrowsableDebugger. Browsable. State. Never. public string Last. Name. Our view updates to You can learn more about attributes that control the debugger data window views here. There are several other attributes that can control the behavior and look of the debugger, that well likely talk about in future postsGem 4 Applying view customizations to framework types. You may not always control the source for the types that youd like to make easier to view. Imagine you have the following class. Program. staticvoid Mainstring args. IPHost. Entry host. Entry Dns. Get. Host. Entrybing. It sure would be nice if IPHost. Entry showed the Host. Name property in the value column, without having to expand it. The Debugger. Display. Attribute has an optional parameter for Target. Type. This can be used in conjunction with setting the Debugger. Display. Attribute at the assembly level, to customize types even when you cannot modify their source. Visual Studio ships with a file called autoexp. Common. 7PackagesDebuggerVisualizersOriginal. This file already has several Debugger. Display attributes that customize common framework types. We can modify it from an elevated command prompt and add the following assembly Debugger. DisplayHost Host. Name, Target typeofIPHost. Entry. We then compile it, again from an elevated developer command prompt, with the command line csc t library autoexp. The next time we debug our program, well now see This allows for powerful, time saving, customizations of your own types, frameworks you ship to others, and any code on which you depend. Although the examples above focus on managed code, similar customizations can be made to the C debugging experience, including global view modifications via autoexp. Gem 5 Snippets. The tips above are focused on debugging code thats already been written. What about when you need to pump out new code quickly I expect many of you may already be familiar with the built in Code Snippets, but its worth mentioning that Snippets are extensible. There are default directories that are registered where you can store your own code snippets. For example, for C, that location is userprofileDocumentsVisual Studio 2. Code SnippetsVisual CMy Code Snippets. In 2. 00. 5, when Snippets were first introduced, a common demo of adding a new snippet for C was to create a dim snippet, so that you wouldnt have to enter the type name twice when instantiating a type in C. The introduction of implicitly typed local variables via var somewhat eliminated the need for such a snippet however, some coding guidelines preclude using var as it can impact readability. So, lets introduce a new var snippet, called var. Code. Snippets xmlnshttp schemas. Visual. Studio2. Code. Snippet. Code. Snippet. Format1. Header. lt Title Varlt Title. Shortcut varlt Shortcut. Description Code snippet for instantiating an object with full type infolt Description. Author Anson Hortonlt Author. Snippet. Types. Snippet. Type Expansionlt Snippet. Type. lt Snippet. Types. lt Header. Snippet. lt Declarations. Literal. lt ID typelt ID. Default Examplelt Default. Tool. Tip The type to constructlt Tool. Tip. lt Literal. Literal. ID variablelt ID. Default examplelt Default.

Coments are closed
Scroll to top