Problem with code snippet Visual Studio 2015

5

I have a code snippet that according to the syntax is all right, but I can not get the tab stop from the snippet to change to the variables that they are inside the parentheses, on the contrary I click tab , it does not do anything, I click again on tab and it moves to the last substitution variable, here is the declaration of the code snippet :

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Set de la clase de Negocio</Title>
      <Author>Jorge Torselli</Author>
      <Description>Establece el set modificado para el campo</Description>
      <Shortcut>set</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>Nombre_set</ID>
          <ToolTip>Escribir el nombre del campo en cuestión</ToolTip>
        </Literal>
        <Literal>
          <ID>Tipo_dato</ID>
          <ToolTip>Escribir el tipo de dato en cuestión</ToolTip>
        </Literal>
        <Literal>
          <ID>Nueva_asignacion</ID>
          <ToolTip>El tipo de dato y nombre que se le asignara</ToolTip>
        </Literal>
        <Literal>
          <ID>Nombre_campo</ID>
          <ToolTip>EL nombre del campo al que hace referencia = al que se le asigno</ToolTip>
        </Literal>
      </Declarations>
      <Code Language="CSharp">
        <![CDATA[public void set$Nombre_set$($Tipo_dato$  $Nueva_asignacion$) { this$Nombre_campo$ = $Nueva_asignacion$; }]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

I am using Visual Studio Community 2015, when I add the snippet to Visual Studio I follow the steps that are in the MSDN tutorial of code snippets .

    
asked by Jorge Torselli 08.08.2017 в 02:37
source

1 answer

3

I have found a way to solve it, I needed some labels and organize the code in a better way, I put the edited and functional code ....

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>set</Title>
      <Shortcut>set</Shortcut>
      <Description>Fragmento de código para set personalizado</Description>
      <Author>Jorge Torselli</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>nombre</ID>
          <Default>nombre</Default>
          <ToolTip>Nombre del set</ToolTip>
        </Literal>
        <Literal>
          <ID>tipo</ID>
          <Default>int</Default>
          <ToolTip>Tipo de variable</ToolTip>
        </Literal>
        <Literal>
          <ID>variable</ID>
          <Default>x</Default>
          <ToolTip>Nombre de variable</ToolTip>
        </Literal>
        <Literal>
          <ID>campo</ID>
          <Default>y</Default>
          <ToolTip>Nombre de campo</ToolTip>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[Public void set$nombre$ ( $tipo$ $variable$ ) { this$campo$ = $variable$; } $end$]]>
    </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

I added the SnippetType tag and placed inside this Expansion; this allows inserting the snippet where the cursor is placed, this kind of snippet makes visual studio understand that the snippet will serve to generate type definitions, definitions of class members and common code constructors.

I added default values in the variables, so that the default value has to be replaced, that even if a snippet is used with a value that is almost always the same it can be added leaving the option to change it when necessary.

I added the end $ end $ for the cursor to be placed after having expanded the code snippet.

I also ordered the tag code with indentations according to the hierarchy for easier understanding of the code.

This is the link where I found the information that I just wrote ...

link

    
answered by 08.08.2017 / 21:31
source