简体   繁体   中英

$selected$ only used once in custom visual studio c# snippet

My custom snippet only include $selected$ once. How can I use $selected$ multiple times?

Snippet :

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
      <Title>Creates a collection using ICollection from the selected entity</Title>
      <Author>Stein Lundbeck</Author>
      <Description>Select entity and the snippet implements ICollection with the selected entity</Description>
      <Shortcut>icoll</Shortcut>
      <Keywords>
        <Keyword>C#</Keyword>
        <Keyword>Collection</Keyword>
        <Keyword>Entity</Keyword>
      </Keywords>
    </Header>
    <Snippet>
    <Imports>
        <Import>
          <Namespace>System.Collections.Generic</Namespace>
        </Import>
        <Import>
          <Namespace>System.Collections.ObjectModel</Namespace>
        </Import>
    </Imports>
    <Declarations>
        <Literal Editable="true">
            <ID>Name</ID>
            <ToolTip>Name of variable</ToolTip>
            <Default>myVar</Default>
        </Literal>
    </Declarations>
        <Code Language="csharp" Delimiter="$" Kind="file">
            <![CDATA[ICollection<$selected$> $Name$ = new Collection<$selected$>();

            $end$]]>      
        </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Output :

using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Test
{
    class MyClass
    {
        ICollection<int> myVar = new Collection<>();
    }  
}

The Collection<> is missing the value from $selected$

Check this MSDN reference for the Code Snippets Schema

"You may not use either $end$ or $selected$ more than once in a code snippet."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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