參考:https://www.cnblogs.com/actberw/archive/2010/04/09/1708395.html(vs中的code snippet技術)
步驟1:寫代碼
<?xml version ="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Property Of ViewModel</Title>
<Shortcut>vmp</Shortcut>
<Description>Property Of ViewModel</Description>
<Author>soeasy</Author>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>DataType</ID>
<ToolTip>data type of the property</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>PropertyName</ID>
<ToolTip>property name</ToolTip>
<Default>Prop1</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
#region $PropertyName$
$DataType$ _$PropertyName$;
public $DataType$ $PropertyName$
{
get{
return _$PropertyName$;
}
set{
SetProperty(ref _$PropertyName$,value);
}
}
#endregion
$end$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
步驟2:存成 soeasy.snippet
步驟3:vs>工具>代碼片斷管理器,導入,選擇 My Code Snippet
文件會存放在 C:\Users\cqsir\Documents\Visual Studio 2017\Code Snippets\Visual C#\My Code Snippets
疑問:不懂為什么,在代碼片斷管理器里,選中My Code Snippet時,沒有顯示預覽。但是實際上這個snippet是可用的。