Visual studio 2010 在VS 2010中,我可以用一个代码片段替换多个项目吗

Visual studio 2010 在VS 2010中,我可以用一个代码片段替换多个项目吗,visual-studio-2010,code-snippets,Visual Studio 2010,Code Snippets,我有一个非常简单的代码snitppet,如下所示: <asp:Label Text="$Name$" runat="server" AssociatedControlID="$txtName$" /> <asp:TextBox runat="server" ID="$txtName$" /> <br /> 我所希望的是,$txtName$在这两个地方都会被更改,但事实并非如此,只更改了第一个实例,我甚至无法切换到第二个实例 有什么解决办法吗?这应该对我

我有一个非常简单的代码snitppet,如下所示:

<asp:Label Text="$Name$" runat="server" AssociatedControlID="$txtName$" />
<asp:TextBox runat="server" ID="$txtName$" />
<br />


我所希望的是,
$txtName$
在这两个地方都会被更改,但事实并非如此,只更改了第一个实例,我甚至无法切换到第二个实例


有什么解决办法吗?

这应该对我有用

可以显示完整的代码段文件吗?这是一个有效的方法,
type
fieldName
被多次替换:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <Header>
        <Title>Non-automatically implemented property</Title>
        <Author>Richard Cox</Author>
        <Shortcut>propf</Shortcut>
        <Description>Property with exlicit field</Description>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>propName</ID>
                <ToolTip>Property Name</ToolTip>
                <Default>Name</Default>
            </Literal>
            <Literal>
                <ID>fieldName</ID>
                <ToolTip>Field Name</ToolTip>
                <Default>field</Default>
            </Literal>
            <Literal>
                <ID>type</ID>
                <ToolTip>Property type</ToolTip>
                <Default>string</Default>
            </Literal>
        </Declarations>
        <Code Language="csharp">
            <![CDATA[private $type$ $fieldName$;
    public $type$ $propName$ {
        get { return $fieldName$;}
        set { $fieldName$ = value;}
    }

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

非自动实现的属性
理查德·考克斯
道具
具有exlicit字段的属性
膨胀
专有名称
属性名
名称
字段名
字段名
领域
类型
属性类型
一串



这应该对我有用

可以显示完整的代码段文件吗?这是一个有效的方法,
type
fieldName
被多次替换:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <Header>
        <Title>Non-automatically implemented property</Title>
        <Author>Richard Cox</Author>
        <Shortcut>propf</Shortcut>
        <Description>Property with exlicit field</Description>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>propName</ID>
                <ToolTip>Property Name</ToolTip>
                <Default>Name</Default>
            </Literal>
            <Literal>
                <ID>fieldName</ID>
                <ToolTip>Field Name</ToolTip>
                <Default>field</Default>
            </Literal>
            <Literal>
                <ID>type</ID>
                <ToolTip>Property type</ToolTip>
                <Default>string</Default>
            </Literal>
        </Declarations>
        <Code Language="csharp">
            <![CDATA[private $type$ $fieldName$;
    public $type$ $propName$ {
        get { return $fieldName$;}
        set { $fieldName$ = value;}
    }

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

非自动实现的属性
理查德·考克斯
道具
具有exlicit字段的属性
膨胀
专有名称
属性名
名称
字段名
字段名
领域
类型
属性类型
一串



结果是替换工作正常,但与我键入的不一样。因此,我可以键入所需的内容,然后要更改其他属性,我必须将焦点从代码段移开,因此按下向下箭头键即可完成此工作。

结果表明,替换工作正常,但与我键入的内容不同。因此,我可以键入所需内容,然后要更改其他属性,我必须将焦点从片段上移开,因此按下向下箭头键即可。当您希望使用$selected$创建两次环绕片段时,有趣的场景开始了。例如,创建CheckArgumentForNull代码段以检查参数是否为null,如果为null,则使用参数名称引发ArgumentNullException。后来才被替换

有什么想法吗?当然,我们可以自己使用扩展代码段和类型参数名

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
      <Title>notnull</Title>
      <Author>Viiar Consulting</Author>
      <Description>Code snippet for checking whether is argument null</Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>notnull</Shortcut>
    </Header>
    <Snippet>
      <Imports>
        <Import>
          <Namespace>System</Namespace>
        </Import>
      </Imports>
      <Declarations>
        <Literal Editable="true">
          <ID>argument</ID>
          <ToolTip>
          </ToolTip>
          <Default>argument</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[if ($selected$ == null)
{
    throw new ArgumentNullException("$selected$");
}
$end$]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

膨胀
周边地区
notnull
维亚尔咨询公司
用于检查参数是否为null的代码段
notnull
系统
论点
论点


当您想用$selected$创建两次环绕片段时,有趣的场景就开始了。例如,创建CheckArgumentForNull代码段以检查参数是否为null,如果为null,则使用参数名称引发ArgumentNullException。后来才被替换

有什么想法吗?当然,我们可以自己使用扩展代码段和类型参数名

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
      <Title>notnull</Title>
      <Author>Viiar Consulting</Author>
      <Description>Code snippet for checking whether is argument null</Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>notnull</Shortcut>
    </Header>
    <Snippet>
      <Imports>
        <Import>
          <Namespace>System</Namespace>
        </Import>
      </Imports>
      <Declarations>
        <Literal Editable="true">
          <ID>argument</ID>
          <ToolTip>
          </ToolTip>
          <Default>argument</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[if ($selected$ == null)
{
    throw new ArgumentNullException("$selected$");
}
$end$]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

膨胀
周边地区
notnull
维亚尔咨询公司
用于检查参数是否为null的代码段
notnull
系统
论点
论点


ENTER
是执行此操作的正常方式,它完成插入代码段的过程。按
ENTER
是执行此操作的正常方式,它完成插入代码段的过程。