在2005中,输入prop然后按tab,他就会自动出现        private List<Card> _All;
        public List<Card> All
        {
            get
            {
                return _All;
            }
            set
            {
                _All = value;
            }
        }
可是在2008,他已经简化为public int MyProperty { get; set; }我想问,怎样设置才能在2008中使用自动填充的代码格式为2005的那个

解决方案 »

  1.   

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/maseccc/archive/2009/01/22/3850287.aspxvs 2005 中自动生成属性(Property)的代码段的方法:在代码中输入prop ,然而按Tab键,就会自动生成Property的框架,如:view plaincopy to clipboardprint?
    private int myVar;   
    public int MyProperty   
    {   
        get { return myVar; }   
        set { myVar = value; }   
    }   
            private int myVar;
            public int MyProperty
            {
                get { return myVar; }
                set { myVar = value; }
            }  在vs 2008中通过输入porp ,自动生成的代码段不是vs2005 中的格式,如:view plaincopy to clipboardprint?
    public int MyProperty { get; set; }  
     public int MyProperty { get; set; } 这种定义方式是c# 3.0的新特性:自动属性(Automatic Properties),但在.net 2.0的项目中不支持自动属性,下面介绍如何在vs 2008 中自动生成如vs 2005格式的Property代码段。1 新建一个proc.snippet文件内容如下:view plaincopy to clipboardprint?
    <?xml version="1.0" encoding="utf-8" ?>   
    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">   
    <CodeSnippet Format="1.0.0">   
    <Header>   
    <Title>propc</Title>   
    <Shortcut>propc</Shortcut>   
    <Description>Code snippet for 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>  
    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
    <Header>
    <Title>propc</Title>
    <Shortcut>propc</Shortcut>
    <Description>Code snippet for 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>
       2 拷贝此文件到:C:\Documents and Settings\[User]\My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets目录中。此时就可通过在代码中输入propc ,获得如vs 2005格式的代码段了。
      

  2.   

    这个叫code snippets在tools ->Code snippets manager  管理自己的code snippets,可以自己定制的
      

  3.   

    D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#
    这个c#默认的代码段  vs自带的
      

  4.   

    08已经不用05的格式了  他自己会创建内部私有变量用来存储值    ,在08中也支持05的写法   可以用prop
    再加两下Tab键  完成一个属性的定义