【发布时间】:2012-11-28 00:48:58
【问题描述】:
编辑:这可以关闭。找到一个完全相同的副本,似乎没有解决方案。 =(
完全重复: Formatting Literal parameters of a C# code snippet
在编写 sn-p 时有什么方法可以解析替换文字吗?我想做类似以下的事情:
<Literal>
<ID>PropertyName</ID>
</Literal>
用户将 PropertyName 替换为“MyProperty”,结果如下:
private object _myProperty;
public object MyProperty
{get;set;}
注意大写。我需要一种方法来解析替换文字并对其进行操作。下划线是微不足道的,只是硬编码的问题。
这里有机会吗?
编辑;完整的sn-p:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MVVM Public Property</Title>
<Author>Michael Leide</Author>
<Description>Adds a public property with private backing and property changed event support.</Description>
<Shortcut>propvm</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>PropertyType</ID>
<Default>object</Default>
</Literal>
<Literal Editable="true">
<ID>PropertyName</ID>
<Default>PropertyName</Default>
</Literal>
</Declarations>
<Code Language="csharp" Kind="" Delimiter="$">
<![CDATA[
$PropertyType$ _$PropertyName$;
public $PropertyType$ $PropertyName$ {
get {
if (_$PropertyName$ == null)
_$PropertyName$ = new $PropertyType$();
return _$PropertyName$;
} set {
_$PropertyName$ = value;
this.OnPropertyChanged("$PropertyName$");
} }
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
【问题讨论】:
-
你能发布你的完整sn-p吗?
-
你明白了。如最初所述,我想将 PropertyName 转换为 _propertyName。
标签: c# xml visual-studio code-snippets