• Visual Studio 小技巧:自定义代码片断


    用鼠标点点Visual Studio,会发现有个代码片断菜单: 
    点开后发现,原来是常用的代码片断(Tab的快捷方式)的管理器:
    于是打开上面的文件夹路径:
    通过经验或者直觉可知:要自定义代码片断,只要把文件复制一份,改改名称和参数,然后导入就应该可以了:
    下面我就演示下MAction类来示例:
    我把if.snippet复制了一份,改名为maction.snippet,然后用vs打开,发现是个xml:
    <?xml version="1.0" encoding="utf-8"?>
    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
    <Header>
    <Title>if</Title>
    <Shortcut>if</Shortcut>
    <Description>if 语句的代码段</Description>
    <Author>Microsoft Corporation</Author>
    <SnippetTypes>
    <SnippetType>Expansion</SnippetType>
    <SnippetType>SurroundsWith</SnippetType>
    </SnippetTypes>
    </Header>
    <Snippet>
    <Declarations>
    <Literal>
    <ID>expression</ID>
    <ToolTip>要计算的表达式</ToolTip>
    <Default>true</Default>
    </Literal>
    </Declarations>
    <Code Language="csharp"><![CDATA[if ($expression$)
    {
    $selected$ $end$
    }]]>
    </Code>
    </Snippet>
    </CodeSnippet>
    </CodeSnippets>
     

    扫了一下,发现这xml很简单,只要修改Shortcut(敲打的前几个字母),和Code里的内容改成自己的就可以了,当然描述和参数和表达式,有需要自己也可以改:

     

    OK,改完就这样了,本来以为还要导入,却发现,在默认目录里复制是直接生效的。


    测试,直接敲ma:
     

    直接出来代码片断的提示了,双击Tab按钮,直接出来了代码片断:

                using (MAction action = new MAction(光标是定位在这里的))
                {
                    
                }
     

    是不是很简单的说,通过此方法,把常用的代码片断弄成2个字母快捷方式(Tab),可以提高平时的编码速度。


    不知道这个VS小技巧有多少人已经使用过了,知道并已使用的可点下反对,不知道或没使用的可以点下推荐。

  • 相关阅读:
    开源大数据周刊-第29期
    rsync
    Tomcat基础教程(四)
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    python 取前10位
    python 字典统计次数
    阿里开源分布式事务Fescar demo示例
  • 原文地址:https://www.cnblogs.com/cyq1162/p/3135373.html
Copyright © 2020-2023  润新知