-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultValueSnippet.snippet
60 lines (55 loc) · 2.09 KB
/
DefaultValueSnippet.snippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Struct with DefaultValue pattern</Title>
<Shortcut>dvpattern</Shortcut>
<Description>Inserts the DefaultValue Pattern at the current location of the struct</Description>
<Author>Eik Rentzow</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Function>ClassName()</Function>
<Default>ClassNamePlaceholder</Default>
</Literal>
<Literal Editable="true">
<ID>ctorcontent</ID>
<ToolTip>Custom parameterless constructor code</ToolTip>
<Default>/* Put your custom c'tor code here */</Default>
</Literal>
<Literal Editable="true">
<ID>fieldinit</ID>
<ToolTip>Field initializers</ToolTip>
<Default>/* Put your custom field initializers here */</Default>
</Literal>
</Declarations>
<Code Language="csharp" Format="CData">
<![CDATA[
#region Default Value Pattern
public static $classname$ DefaultValue = new $classname$()
{
$fieldinit$
};
public $classname$(object dummy)
{
this = DefaultValue;
$ctorcontent$
}
public static $classname$[] NewArray(int capacity)
{
var temp = new $classname$[capacity];
for (int i = temp.Length - 1; i >= 0; --i) temp[i] = DefaultValue;
return temp;
}
private static $classname$ @__default = default($classname$);
public bool IsInitialized => !@__default.Equals(this);
#endregion ]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>