[ Log On ]

为visual studio 2008配置带私有变量的prop

vs 2005下prop会出来private的field和public的property,但是到了vs2008下面prop只会产生public的property,我们需要手动增加一下。把下面这段命名为propp.snippet或者其他你喜欢的名字,然后放到这里就行了(注意vs安装路径也许不同):[quote]D:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets[/quote]
下面是配置文件(顺便测试一下代码发芽,很早就听说了,今天用了感觉很不错):
    

XML语言: visual studio 2008 snippet配置
    
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>propp</Title>
      <Shortcut>propp</Shortcut>
      <Description>Code snippet for VS2005 property and backing field</Description>
      <Author>Microsoft Corporation</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>
        <Literal>
          <ID>field</ID>
          <ToolTip>The variable backing this property</ToolTip>
          <Default>myVar</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[private $type$ $field$;

  public $type$ $property$
  {
    get { return $field$;}
    set { $field$ = value;}
  }
  $end$]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Posted by: 狐狸 发表于: 10/8/2008 3:14:15 AM | 4438天11小时46分钟前
完全不懂!!!但是因为沙发所以我一定要坐!!!

Add your Comment


Supported UBB tags: [b],[u],[i],[color]