-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexenum.snippet
More file actions
75 lines (70 loc) · 2.64 KB
/
exenum.snippet
File metadata and controls
75 lines (70 loc) · 2.64 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2010/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>列挙体の拡張メソッドパターン</Title>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Shortcut>exenum</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>enumName</ID>
<ToolTip>拡張対象の列挙体名</ToolTip>
<Default>EnumName</Default>
</Literal>
<Literal>
<ID>returnType</ID>
<ToolTip>拡張メソッドの戻り値のとなるプロパティの型</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>propertyName</ID>
<ToolTip>拡張メソッドの戻り値のとなるプロパティ名</ToolTip>
<Default>PropertyName</Default>
</Literal>
</Declarations>
<Code Language="csharp" Kind="type decl">
<![CDATA[ /// <summary>
/// <see cref="$enumName$"/>の拡張メソッドを定義するクラスです。
/// </summary>
public static class $enumName$Extensions
{
private class $enumName$Info
{
public $returnType$ $propertyName$ { get; private set; }
public $enumName$Info($returnType$ property)
{
$propertyName$ = property;
}
}
private static Dictionary<$enumName$, $enumName$Info> _infoes = new Dictionary<$enumName$, $enumName$Info>();
[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
static $enumName$Extensions()
{
// TODO : Write your implementation
// _infoes.Add($enumName$., new $enumName$Info());
}
public static $returnType$ Get$propertyName$(this $enumName$ source)
{
return GetInfo(source).$propertyName$;
}
private static $enumName$Info GetInfo($enumName$ source)
{
$enumName$Info info;
if (_infoes.TryGetValue(source, out info) && info != null)
{
return info;
}
else
{
throw new InvalidOperationException(string.Format("[{0}] is not supported.", source));
}
}
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>