Saturday, 22 March 2014

code snippets in c#

Basically custom snippets save in .snippet file, it is XML based file, and we can manually create this XML file in a snippet acceptable format and add it into Visual Studio IDE

1.      Adding custom snippet to VS2010.
2.      Click on Tools à Code Snippet manager [ctrl + k, ctrl + b]
3.      Adding New code snippet by clicking to Import
4. Choose the location for it by;
4.      Shortcut which you have given in snippet file just type there
Commant
      comnt
5.      It displaying on your snippet window like below
6.      By typing it fully your code come in editor;
code snippet sample
xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Commant</Title>
      <Shortcut>comnt</Shortcut>
      <Description>
        Code snippet for Commenting the code
      </Description>
      <Author>Satya</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>USID</ID>
          <ToolTip>User Story Id</ToolTip>
          <Default>UserStoryId</Default>
        </Literal>
        <Literal>
          <ID>CreatedBY</ID>
          <ToolTip>Created By</ToolTip>
          <Default>XXXXXXXX</Default>
        </Literal>
        <Literal>
          <ID>CreatedOn</ID>
          <ToolTip>Created Date on</ToolTip>
          <Default>MM/DD/YYYY</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[
/// User Story detail - $USID$
///Created By - $CreatedBY$ on Created Date  - $CreatedOn$
    ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

No comments:

Post a Comment

Others

You will like to read it