2015-09-23 47 views
0

Creating Custom Code Snippet对我没有多大帮助。我的问题是特定于我的要求。在VS2013中为C创建自定义代码片段#

我想为我的Property写一个自定义代码片段。这种情况通常是,当我们写prop和双标签,我们将得到的输出

public int MyProperty { get; set; } 

,当我们写propfull我们,只要我们改变变量名,它会自动反映得到

private int myVar; 

public int MyProperty 
{ 
    get { return myVar;} 
    set { myVar = value;} 
} 

到处

现在我想要写我自己的网页摘要

public int MyProperty 
{ 
    get 
    { 
     return GetValue(() => MyProperty); 
    } 
    set 
    { 
     SetValue(() => MyProperty, value); 
    } 
} 

我有Creating a Code Snippet从MSDN

这是我曾尝试

<?xml version="1.0" encoding="utf-8"?> 
<CodeSnippets 
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> 
    <CodeSnippet Format="1.0.0"> 
     <Header> 
      <Title>propmy</Title> 
     </Header> 
     <Snippet> 
      <Code Language="csharp"><![CDATA[public int MyProperty 
     { 
       get { return GetValue(() => MyProperty); } 
       set { SetValue(() => MyProperty , value); } 
     } 
$end$]]> 
      </Code> 
     </Snippet> 
    </CodeSnippet> 
</CodeSnippets> 

但是,当我在VS IDE写并不propmy在列表中显示出来,它truns在第一托选项卡上,并在第二个选项卡上创建属性,如正常。我不知道如何继续?

回答

1

您可以尝试在你的XML的标题部分添加

<Shortcut>propmy</Shortcut> 

。我相信这将这样的伎俩

编辑:

我创建了完整的XML为您服务。只需复制粘贴,它会帮助你。

<?xml version="1.0" encoding="utf-8" ?> 
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> 
    <CodeSnippet Format="1.0.0"> 
     <Header> 
      <Title>propmy</Title> 
      <Shortcut>propmy</Shortcut> 
      <Description>Automatically implemented property</Description> 
      <Author>BugFree</Author> 
      <SnippetTypes> 
       <SnippetType>Expansion</SnippetType> 
      </SnippetTypes> 
     </Header> 
     <Snippet> 
      <Declarations> 
       <Literal> 
        <ID>type</ID> 
        <ToolTip>Property type</ToolTip> 
        <Default>int</Default> 
       </Literal> 
       <Literal> 
        <ID>property</ID> 
        <ToolTip>Property name</ToolTip> 
        <Default>MyProperty</Default> 
       </Literal> 
      </Declarations> 
      <Code Language="csharp"><![CDATA[public $type$ $property$ 
     { 
       get { return GetValue(() => $property$); } 
       set { SetValue(() => $property$ , value); } 
     } 
$end$]]> 
      </Code> 
     </Snippet> 
    </CodeSnippet> 
</CodeSnippets>