This project is read-only.

Singleton

Nov 24, 2008 at 3:30 PM
Here's a really old version

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Singleton Code Snippet</Title>
      <Shortcut>singl</Shortcut>
      <Description>Adds plumbing to make class a singleton.</Description>
      <Author>Dmitri Nesteruk</Author>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>ClassName</ID>
          <ToolTip>Name of the surrounding class.</ToolTip>
          <Default>ClassName</Default>
        </Literal>
      </Declarations>
      <Code Language="CSharp">
<![CDATA[
    private $ClassName$() { /* nothing here */ }
    
    class $ClassName$Maker {
      static $ClassName$Maker () { }
      internal static readonly $ClassName$ instance = new $ClassName$();
    }
    
    /// <summary>
    /// Gets the unique instance of this <see cref="ClassName"/>.
    /// </summary>
    /// <value>The unique instance.</value>
    public static $ClassName$ Instance {
      get { return $ClassName$Maker.instance; }
    }
]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>