编写VS的Snippet

参考: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是可用的。

转载于:https://www.cnblogs.com/erentec/p/11064617.html

猜你喜欢

转载自blog.csdn.net/weixin_34357267/article/details/93691124