简体   繁体   English

程式码片段有问题

[英]Having trouble with code snippet

Hi I have this code snippet to write set properties more faster on a class, but I just dont know why it just doesn't work the tab stop inside the parenthesis, here is the definition for the 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</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>

It is on Visual Studio 2015 community, the tab stop it is only working on the first declaration wich is Nombre_set, from Nombre_set it jumps to Nombre_campo skipping declaration Tipo_dato, and Nueva_asignacion... 它位于Visual Studio 2015社区上,仅在第一个声明为Nombre_set时才使用制表位,从Nombre_set跳转到Nombre_campo,跳过声明Tipo_dato和Nueva_asignacion ...

Any suggestions... 有什么建议么...

I found the way to solve it, I needed some tags and organize the code, here is 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 it inside Expansion; 我添加了SnippetType标记并将其放置在Expansion中; This allows you to insert the snippet where the cursor is placed. 这使您可以将代码段插入光标所在的位置。 This snippet class makes visual studio understand that the snippet will be used to generate type definitions, member definitions and common code constructors. 此代码段类使Visual Studio理解该代码段将用于生成类型定义,成员定义和通用代码构造函数。

I added default values ​​in the variables, so you have to replace the default value, that even if you use a snippet with a value that is almost always the same can be added, leaving the option to change it when necessary. 我在变量中添加了默认值,因此您必须替换默认值,即使您使用的代码段的值几乎总是相同,也可以添加该值,并保留在必要时进行更改的选项。

I added $end$ so that the cursor is placed after the code snippet has been expanded. 我添加了$ end $,以便将光标放在代码段扩展之后。

I also ordered the tag code with indents according to the hierarchy for easier understanding of the code. 我还根据层次结构对带有缩进的标记代码进行了排序,以便于理解代码。

This is the link where I found the information I just wrote ... 这是我找到我刚刚写的信息的链接...

https://msdn.microsoft.com/en-us/library/ms379562(v=vs.80).aspx https://msdn.microsoft.com/zh-CN/library/ms379562(v=vs.80).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM