locked
use $selected$ value in multiple places in custom snippet RRS feed

  • Question

  • I need to use the $selected$ value in multiple places in my snippet, but it only works one and renders blank after that.

    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>Variable name</ToolTip>
                <Default>myVar</Default>
            </Literal>
        </Declarations>
            <Code Language="csharp" Delimiter="$" Kind="file">
                <![CDATA[ICollection<$selected$> $Name$ = new Collection<$selected$>(); $end$]]>      
            </Code>
        </Snippet>
      </CodeSnippet>
    </CodeSnippets>
    

    I apply the snippet to: int

    Output:

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

    The int type is only used once, even though it should be used in both ICollection<> and Collection<>

    Friday, May 29, 2020 6:24 AM

All replies