如何在 VS2008 代码片段中强制使用大写?
我决定采用以下创建属性的风格(带有支持字段):
private _firstName;
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
鉴于属性的名称与支持字段的名称相似,我改进了内置的 prop
片段如下:
<?xml version="1.0"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>prop</Title>
<Author>Frank Rizzo</Author>
<Description>Code snippet for property and backing field - changed one (not the original).</Description>
<Shortcut>prop</Shortcut>
<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$ $field$
{
get { return _$field$;}
set { _$field$ = value;}
}
$end$
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
这在一定程度上有效,但支持字段和属性名称的大小写始终相同,按照我的约定,支持字段是驼峰式大小写,而属性名称是帕斯卡大小写。
所以我的问题是:代码片段语法是否有办法更改属性的第一个字母,以便代码片段符合我的约定?
I've settled on the following style of creating properties (with a backing field):
private _firstName;
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
Given that the name of the property is similar to the name of the backing field, I've improved the built in prop
snippet to the following:
<?xml version="1.0"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>prop</Title>
<Author>Frank Rizzo</Author>
<Description>Code snippet for property and backing field - changed one (not the original).</Description>
<Shortcut>prop</Shortcut>
<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$ $field$
{
get { return _$field$;}
set { _$field$ = value;}
}
$end$
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
This works to a degree, but the casing of the backing field and the property name is always the same, where as in my convention, the backing field is camel-cased, where as the property name is pascal-cased.
So my question is this: does the snippet syntax have a way to change the first letter of the property, so that the snippet might comply with my convention?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,这是不可能的(目前)。
希望 Visual Studio 的未来版本能够实现这一点。
Unfortunately, this is not possible (yet).
Hopefully, it will be possible in a future version of Visual Studio.