Code Snippets In Visual Studio 2010

Páginas: 3 (637 palabras) Publicado: 24 de abril de 2012
Code Snippets in Visual Studio 2010



We Recommend These Resources
Java Enterprise Performance
Micro Focus Silk Performer
Micro Focus SilkTest 2011
Innovate Faster in the Cloud with aPlatform as a Service
Developing .NET/C# Applications with VoltDB

Visual Studio allows developers to save snippets of code which can be inserted at a later time. This saves on retyping blocks of codethat are used often. I also find it very useful when I have to show code during presentations. Instead of typing everything live, I find it far easier to simply add the code block by block using codesnippets.

VS 2010 improves the snippet functionality, and makes it easier to create code snippets. There’s two types of snippets:
- Expansion snippets are inserted at the cursor
- SurroundsWithsnippets wraps around selected code

Creating a Custom Snippet:

Let’s go ahead and create a try-catch-finally Expansion snippet:
- Insert a new XML file to the project and call itTryCatchFinally.snippet. Make sure the file name ends with .snippet
- Right-click on the editor window and select Insert Snippet->Snippet. This creates a basic XML snippet template as shown below:
view sourceprint?
01.
03.
04. title
05. author
06. shortcut
07. description
08.
09. SurroundsWith
10. Expansion
11.
12.
13.
14.
15.
16. name
17.value
18.
19.
20.
21.
22. $name$
23. $selected$ $end$]]>
24.
25.
26.

- As you can see, by default the template contains both snippet types.Since I am creating an Expansion snippet, let’s go ahead and get rid of the SurroundsWith tag.
- Update the Title to "Try Catch Finally", Shortcut to "trycf" and Description to "Adds a try-catch-finallyblock".
- Literal tag enables us to define editable values that are inserted into the snippet. In the try-catch-finally snippet, we want to allow the user to change the type of the Exception being...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Visual Studio 2010
  • 60 Propiedades De Visual Studio 2010
  • Creando instaladores en visual studio 2010
  • Programas Hechos En Visual Studio 2010
  • Componente Prinform Visual Studio 2010
  • Manual De Instalación De “Microsoft Visual Studio 2010”
  • Manual para aprender a usar visual studio 2010
  • Visual studio 2010 novedades

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS