APress Visual Studio Condensed

Page 223

Chapter 9 ■ Extending Visual Studio

The next step is to create a provider class that implements IViewTaggerProvider. This class must use some attributes, like Export, before you can use the MEF plug-in system that Visual Studio uses. You can also provide other attributes, like the context type, the tag type, and the order. Finally, you must create at least one ISmartTagAction. The action appears once the tagger has found a match. Our class that inherits from ITagger has a method called GetSmartTagActions, which gives actions that are added and returned. These actions must inherit from ISmartTagAction. It is possible to define the text to display, the icon to show, the action enable status, and the action that must be invoked for your smart tag. As you saw with the HTML code snippet, if you set your smart tag project to be the startup project, you build the project and run the project. Visual Studio starts a new instance of Visual Studio with the smart tag installed for you to test.

Using an MSIL Disassembler Whatever you are doing, at some point you will have to manipulate DLLs. Even your code is compiled into a DLL. The .NET virtual machine reads Microsoft Intermediate Language (MSIL) code, which is now more often named Common Intermediate Language (CIL). It shows what is in the DLL, not your C# or VB code. CIL provides a standard way to use your chosen language as a common base for .NET. To create a wrap up, when you are compiling from Visual Studio, your C# or VB code is translated into CIL. The CIL is assembled into bytecode and packaged into a DLL. When it is time to execute the code, the CIL assembly is translated into native code. Let’s look at two disassemblers: ildasm.exe and ILSpy.

Using ildasm.exe Visual Studio comes with ildasm.exe, which takes a file and displays the interpreted language. It is possible to see the interpreted language (IL) for .exe or .dll files. The command line that follows is an example of how to execute the tool to generate an output file with the interpreted language.   ildasm MyFile.exe /output:MyFile.il   However, the tool also has a user interface. You can simply execute ildasm and the application will show a menu that lets you choose the file to dissemble to show the interpreted language. This tool can be opened easily by typing ildasm at a Visual Studio developer command prompt. Otherwise, you can find this tool in Visual Studio tools. Figure 9-22 shows the interface that opens to a small class library that does not have a lot of methods. If you double-click one of the methods, a window opens with the IL code of this C# code.   public int Method1(int x) { var result = x; result += Method2(); return result; }

223


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.