在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的那个
public List<Card> All
{
get
{
return _All;
}
set
{
_All = value;
}
}
可是在2008,他已经简化为public int MyProperty { get; set; }我想问,怎样设置才能在2008中使用自动填充的代码格式为2005的那个
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格式的代码段了。
这个c#默认的代码段 vs自带的
再加两下Tab键 完成一个属性的定义