Code snippets


Code snippets

Code snippets are small chunks of reusable code often used to minimize the use of repeated code that is common to other functions. Code snippets are accessed through shortcut keys or the context menu in the Visual Basic (VB), CSharp (C#), and XML code editors in Microsoft Visual Studio. Snippets are available in several forms:
  • Those that act as a sub or function (for VB.NET) or method (for C#)
    Functions may take zero or more input parameters, will perform some operation, and may or may not have a return value. IntelliSense will describe all input and output parameters when you use the function in code.
  • Sections of code that must be inserted in existing code blocks.
    These snippets are pieces of code that act as templates for you to add to an existing member and complete. Usually, code from these snippets will not compile unless you make modifications. In cases where you need to hook up variables in the code snippet to variables or literals in your own code, the section of code that needs modification will be highlighted. Hovering the cursor over the highlighted section of the method snippet will cause a tooltip to appear to help you edit the code appropriately; you can press Tab to cycle through all the items in a snippet which need modification.
  • XML code snippets
    XML code snippets are specifically for use in XML files in Visual Studio. Each ArcGIS Explorer customization requires an "AddIns.xml" file that tells ArcGIS Explorer important information such as the caption and dll location for a customization. XML code snippets can be added to the AddIns.xmlfile in the same way as other code snippets. Use of code snippets is discussed below.

Using the Code Snippets

  1. In the Visual Basic or Visual C# code editor window, right-click the code window at the location you wish to insert a snippet, and choose Insert Snippet from the context menu.
  2. Choose ArcGIS Explorer to see the list of available ArcGIS Explorer snippets. You can navigate the list using the mouse or the arrow keys on your keyboard.
    Scroll through the list of available snippets to determine the functionality you want; a tooltip appears when you hover over a snippet to provide more information on its functionality.
  3. Click the code snippet you wish to insert. Alternatively if you are browsing using the keyboard, navigate to the snippet you wish using the arrow keys and press Enter to insert the snippet. The ArcGIS Explorer snippet code will be inserted in the Code Editor; use the Tab key to iterate through any lines of code which you need to edit in order to hook up the inserted code to your existing variables. 

     
Code Snippets are available to access all of the static members on the Application class, for example the ActiveMapDisplay, Presentation, and SelectedItems properties.