Skip to content

Commit ad946ae

Browse files
committed
First version of DefaultValueSnippet.snippet
1 parent e6bfa8c commit ad946ae

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

DefaultValueSnippet.snippet

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

0 commit comments

Comments
 (0)