自动生成public method的code snippet

看了一下VS 2K8下貌似没有这样的code snippet,于是参照系统snippet写了一个:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>public method</Title>
            <Shortcut>pm</Shortcut>
            <Description>Code snippet public void method</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
            
                <Literal>
                    <ID>returnVal</ID>
                    <ToolTip>Return value</ToolTip>
                    <Default>void</Default>
                </Literal>
                <Literal>
                    <ID>name</ID>
                    <ToolTip>Method name</ToolTip>
                    <Default>Test</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[public $returnVal$ $name$()
    {
        $end$
    }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

将以上内容保存为pm.snippet文件放在D:\Program Files (x86)\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Visual C#目录下(假设VS装在D盘)。打开VS在代码文件里敲pm然后按下tab就能自动生成一个public方法签名了。

以前总结的其他的一些有用的code snippet:

cw    Console.WriteLine()
ctor    构造函数
prop  property
propg  只读property
for  for循环
foreach  foreach循环
testm  单元测试方法
try  try catch
using  using
class  class

其中for, foreach, try, using这些是可以用于surround with的。

原文地址:https://www.cnblogs.com/k330/p/public_method_code_snippet.html