今天看了周金桥大大的一文章,非常好的,里面有“代码段管理器” 一段,看了之后心痒难耐,马上上机实验一下,发现在VS2008下的prop所出的代码与周大大的不一样
而在VS2008下是这样子滴
public int MyProperty { get; set; }
打开prop.snippet文件
- <?xmlversion="1.0"encoding="utf-8"?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippetFormat="1.0.0">
- <Header>
- <Title>prop</Title>
- <Shortcut>prop</Shortcut>
- <Description>自动实现的属性的代码段</Description>
- <Author>MicrosoftCorporation</Author>
- <SnippetTypes>
- <SnippetType>Expansion</SnippetType>
- </SnippetTypes>
- </Header>
- <Snippet>
- <Declarations>
- <Literal>
- <ID>type</ID>
- <ToolTip>属性类型</ToolTip>
- <Default>int</Default>
- </Literal>
- <Literal>
- <ID>property</ID>
- <ToolTip>属性名</ToolTip>
- <Default>MyProperty</Default>
- </Literal>
- </Declarations>
- <CodeLanguage="csharp"><![CDATA[public$type$$property${get;set;}$end$]]>
- </Code>
- </Snippet>
- </CodeSnippet>
- </CodeSnippets>
把这个文件复制一份出来改名为propp.snippet,修改里面的代码为以下内容
- <?xmlversion="1.0"encoding="utf-8"?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippetFormat="1.0.0">
- <Header>
- <Title>propp</Title>
- <Shortcut>propp</Shortcut>
- <Description>自动实现的属性的代码段</Description>
- <Author>MicrosoftCorporation</Author>
- <SnippetTypes>
- <SnippetType>Expansion</SnippetType>
- </SnippetTypes>
- </Header>
- <Snippet>
- <Declarations>
- <Literal>
- <ID>type</ID>
- <ToolTip>属性类型</ToolTip>
- <Default>int</Default>
- </Literal>
- <Literal>
- <ID>property</ID>
- <ToolTip>属性名</ToolTip>
- <Default>MyProperty</Default>
- </Literal>
- <Literal>
- <ID>field</ID>
- <ToolTip>Thevariablebackingthisproperty</ToolTip>
- <Default>myVar</Default>
- </Literal>
- </Declarations>
- <CodeLanguage="csharp"><![CDATA[private$type$$field$;
- public$type$$property$
- {
- get{return$field$;}
- set{$field$=value;}
- }
- $end$]]>
- </Code>
- </Snippet>
- </CodeSnippet>
- </CodeSnippets>
现在再试propp看看,哈哈
周大大原文地址http://blog.csdn.net/zhoufoxcn/archive/2008/09/22/2959316.aspx