代码段:在Visual Studio中自动完成ArgumentNullException

gal*_*ets 3 intellisense autocomplete visual-studio visual-studio-2012

我经常写ac#代码,如下所示:

    void func(object myObject)
    {
        if (myObject == null)
        {
            throw new ArgumentNullException("myObject");
        }
        ...
Run Code Online (Sandbox Code Playgroud)

如何在Visual Studio 2012中为该类型的代码编写自动完成,以便我不必一直输入这个?

gal*_*ets 8

由于没有兴趣,我将通过发布我自己的解决方案来关闭这个问题.将以下文件放入C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC#\Snippets\1033\Visual C#\ifn.snippet将可以解决问题:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
        <Title>ifn</Title>
        <Shortcut>ifn</Shortcut>
        <Description>Code snippet for if (arg==null)</Description>
        <Author>sam green</Author>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
            <SnippetType>SurroundsWith</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>argument</ID>
                <Default>arg</Default>
                <ToolTip>Argument</ToolTip>
            </Literal>
        </Declarations>
        <Code Language="csharp"><![CDATA[if ($argument$ == null)
        {
                    throw new ArgumentException("$argument$");
        }$end$]]>
        </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

1146 次

最近记录:

7 年,8 月 前