在自定义的visual studio c#代码段中,$selected$只使用一次。

问题描述 投票:0回答:1

我的自定义片段只包含一次$selected$。我怎样才能多次使用$selected$?

代码段:

<?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>

产出:

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$

c# visual-studio code-snippets
1个回答
1
投票

查看这个MSDN参考资料以了解 代码片段模式

"在一个代码片段中,你不能多次使用$end$或$selected$。"

© www.soinside.com 2019 - 2024. All rights reserved.