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

1 comment:

Anonymous said...

Well said.