2007-10-05

Create object code snippet

This is another Code Snippet very usefull to me.
You can see in a previous post how to implement it in Visual Studio 2005.


<?xml version="1.0" encoding="utf-8"?>

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

  <CodeSnippet Format="1.0.0">

    <Header>

      <Title>vnew</Title>

      <Shortcut>vnew</Shortcut>

      <Description>Code snippet for create a basic new variable</Description>

      <Author>Red Line .Net</Author>

    </Header>

    <Snippet>

      <Declarations>

        <Literal Editable="true">

          <ID>type</ID>

          <ToolTip>Variable type</ToolTip>

          <Default>Object</Default>

          <Function>

          </Function>

        </Literal>

        <Literal Editable="true">

          <ID>variable</ID>

          <ToolTip>The variable backing this property</ToolTip>

          <Default>myVar</Default>

          <Function>

          </Function>

        </Literal>

        <Literal Editable="true">

          <ID>parameters</ID>

          <ToolTip>Parameters Constructor</ToolTip>

          <Default>

          </Default>

          <Function>

          </Function>

        </Literal>

      </Declarations>

      <Code Language="csharp"><![CDATA[$type$ $variable$ = new $type$($parameters$);]]></Code>

    </Snippet>

  </CodeSnippet>

  <CodeSnippet Format="1.0.0">

    <Header>

      <Title>

      </Title>

      <Shortcut>

      </Shortcut>

      <Description>

      </Description>

      <Author>

      </Author>

    </Header>

    <Snippet>

      <Code Language=""><![CDATA[]]></Code>

    </Snippet>

  </CodeSnippet>

</CodeSnippets>

2007-10-02

NotImplemented Code Snippet

IntelliSense Code Snippets are reusable, task-oriented blocks of code.
This is a example to see

You must create a new file throwNotImplemented.snippet in the \Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets folder in your My Documents folder.
The snippet can be used from VS2005 IDE without another configuration.

Code to write:

<?xml version="1.0" encoding="UTF-8"?>

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

  <CodeSnippet Format="1.0.0">

    <Header>

      <Title>throw NotImplementedException</Title>

      <Author>Red Line .Net</Author>

      <Description>Create a line to throw a NotImplementionException</Description>

      <Keywords>

        <Keyword>"Exception"</Keyword>        

      </Keywords>

      <Shortcut>throwNotImplemented</Shortcut>

    </Header>

    <Snippet>

      <Declarations>

        <Literal>

          <ID>message</ID>

          <Type>String</Type>

          <ToolTip>Reason for not implementation</ToolTip>

          <Default>The method or operation is not implemented.</Default>

        </Literal>

      </Declarations>

      <Code Language="csharp" Kind="method body">

        <![CDATA[throw new NotImplementedException("$message$");

        $selected$$end$]]>

      </Code>

    </Snippet>

  </CodeSnippet>

</CodeSnippets>


To use:
In a class code, write throwNotImplemented, press tab key and the IDE writes a line.

throw new Exception("The method or operation is not implemented.");

You can use the shortcuts using ctrl+K,X and you search the snippet in My Code Snippets folder

More info in http://msdn2.microsoft.com/en-us/library/ms165392(VS.80).aspx