Visual Studio Code snippet for methods?

2019-01-30 10:27发布

In Visual Studio I can type e.g.

for TAB TAB

and a code snippet pops in.

Are there built-in code snippets for private, public, etc. methods as well?

8条回答
放我归山
2楼-- · 2019-01-30 11:22

The code snippet for properties is:

propTABTAB

查看更多
聊天终结者
3楼-- · 2019-01-30 11:23

I made my own snippet for a method. The XML code for it is the following, and you can add it to a file called "my_method.snippet" (or whatever_you_want.snippet) in C:\Users\YOUR_USERNAME\Documents\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets (your path might be different because I use VS2012):

<CodeSnippet Format="1.0.0">
    <Header>
        <Title>method</Title>
        <Shortcut>method</Shortcut>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>access_modifier</ID>
                <Default>private</Default>
            </Literal>
            <Literal>
                <ID>return_type</ID>
                <Default>void</Default>
            </Literal>
            <Literal>
                <ID>name</ID>
                <Default>New_method</Default>
            </Literal>
        </Declarations>
        <Code Language="csharp">
            <![CDATA[$access_modifier$ $return_type$ $name$ ()
    {
    $end$
    }]]>
        </Code>
    </Snippet>
</CodeSnippet>
查看更多
登录 后发表回答