在VS2010中创建自定义的代码段

在VS2010中创建自定义的代码段

Posted on 2010-02-22 20:23 生鱼片 阅读(1392) 评论(2) 编辑 收藏

本文基于Visual Studio 2010 RC版本

1.       在项目中新增一个xml文件为carysn.snippet,然后插入代码段,如下图:

 

clip_image002

 

clip_image004

 

2.       完成后会自动插入代码段模板,我们将模板中相关信息修改后如下:

<?xmlversion="1.0"encoding="utf-8" ?>

<CodeSnippetFormat="1.0.0"xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

  <Header>

    <Title>CarySNTest</Title>

    <Author>Cary</Author>

    <Shortcut>CaryShortcut</Shortcut>

    <Description>It is a test snippet</Description>

    <SnippetTypes>

      <SnippetType>SurroundsWith</SnippetType>

      <SnippetType>Expansion</SnippetType>

    </SnippetTypes>

  </Header>

  <Snippet>

    <Declarations>

      <Literal>

        <ID>Author</ID>

        <Default>Cary</Default>

      </Literal>

    </Declarations>

    <CodeLanguage="CSharp">

      <![CDATA[

      /*--------------------------

      Author:$Author$

      Date:2010-02-22

      --------------------------*/

       class Program

      {

        static void Main(string[] args)

        {

            Console.WriteLine("Hello World!");

        }

      }

      ]]>

    </Code>

  </Snippet>

</CodeSnippet>

3.       打开代码段管理器,如下图:

clip_image006

 

4.导入我们创建好的代码段,如下图:

clip_image008

 

5.然后我们就可以在程序中使用了,如下图:

clip_image010

posted @ 2013-01-30 10:21  王永华  阅读(217)  评论(0编辑  收藏  举报