Singleton code snippet and code template : https://blog.francois.raminosona.com/singleton-snippet-template
<?xml version="1.0" encoding="utf-8"?> | |
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Keywords> | |
<Keyword>Singleton</Keyword> | |
</Keywords> | |
<Title>singleton</Title> | |
<Author>Francois Raminosona</Author> | |
<Description>Adds a singleton pattern to the current class</Description> | |
<Shortcut>singleton</Shortcut> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
</Header> | |
<Snippet> | |
<Code Language="CSharp"> | |
<![CDATA[#region Singleton | |
private static $className$ _instance; | |
public static $className$ Current => _instance ??= new $className$(); | |
#endregion | |
private $className$() | |
{ | |
// TODO : Delete other constructors | |
// TODO : Make $className$ sealed | |
}]]> | |
</Code> | |
<Declarations> | |
<Literal Editable="false"> | |
<ID>className</ID> | |
<Function>ClassName()</Function> | |
<Default>className</Default> | |
</Literal> | |
</Declarations> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
<?xml version="1.0" encoding="utf-8"?> | |
<CodeTemplates version="3.0"> | |
<CodeTemplate version="2.0"> | |
<Header> | |
<_Group>C#</_Group> | |
<Version /> | |
<MimeType>text/x-csharp</MimeType> | |
<Shortcut>singleton</Shortcut> | |
<_Description>Adds a singleton design pattern</_Description> | |
<TemplateType>Unknown</TemplateType> | |
</Header> | |
<Variables> | |
<Variable name="className1" isEditable="false"> | |
<Function>GetCurrentClassName()</Function> | |
</Variable> | |
<Variable name="className2" isEditable="false"> | |
<Function>GetCurrentClassName()</Function> | |
</Variable> | |
<Variable name="className3" isEditable="false"> | |
<Function>GetCurrentClassName()</Function> | |
</Variable> | |
<Variable name="className4" isEditable="false"> | |
<Function>GetCurrentClassName()</Function> | |
</Variable> | |
<Variable name="className5" isEditable="false"> | |
<Function>GetCurrentClassName()</Function> | |
</Variable> | |
</Variables> | |
<Code><![CDATA[#region Singleton | |
private static $className1$ _instance; | |
public static $className2$ Current => _instance ??= new $className3$(); | |
#endregion | |
private $className4$() | |
{ | |
// TODO : Delete other constructors | |
// TODO : Make $className5$ sealed | |
}]]></Code> | |
</CodeTemplate> | |
</CodeTemplates> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment