VS中自定义代码片段

VS - 工具 - 代码片段管理器

实现:propnotify 加 Tab 键 生成属性定义代码片段
(包含一个字段定义,一个属性get/set定义,其中set会触发属性值变更事件)

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>propnotify</Title>
            <Shortcut>propnotify</Shortcut>
            <Description>プロパティとバッキング フィールド用のコード スニペット</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>プロパティの型</ToolTip>
                    <Default>int</Default>
                </Literal>
                <Literal>
                    <ID>property</ID>
                    <ToolTip>プロパティ名</ToolTip>
                    <Default>MyProperty</Default>
                </Literal>
                <Literal>
                    <ID>field</ID>
                    <ToolTip>このプロパティのバッキング変数</ToolTip>
                    <Default>myVar</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[private $type$ $field$;

    public $type$ $property$
    {
        get { return $field$;}
        set
        {
            $field$ = value;
            this.RaisePropertyChange(nameof($property$));
        }
    }
    $end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

猜你喜欢

转载自www.cnblogs.com/CoderMonkie/p/vs-snippet.html