-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnppropget.snippet
More file actions
45 lines (43 loc) · 1.96 KB
/
nppropget.snippet
File metadata and controls
45 lines (43 loc) · 1.96 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
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Cached Get NonPublic Property</Title>
<Shortcut>nppropget</Shortcut>
<Description>Gets a NonPublic Property using cached reflection. Adapted from Nick Chapsas's "Achieving compile-time performance with Reflection in C#"</Description>
<Author>Mike Wagner</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>class</ID>
<ToolTip>The class containing the property.</ToolTip>
<Default>TClass</Default>
</Literal>
<Literal>
<ID>propertytype</ID>
<ToolTip>The type of property.</ToolTip>
<Default>TProperty</Default>
</Literal>
<Literal>
<ID>propertyname</ID>
<ToolTip>The name of property.</ToolTip>
<Default>PropertyName</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
private static readonly PropertyInfo Cached$propertyname$PropertyInfo = typeof($class$).GetProperty("$propertyname$", BindingFlags.NonPublic | BindingFlags.Instance);
private static readonly Func<$class$, $propertytype$> Get$propertyname$Delegate = (Func<$class$, $propertytype$>)Delegate.CreateDelegate(typeof(Func<$class$, $propertytype$>), Cached$propertyname$PropertyInfo.GetGetMethod(true));
public static $propertytype$ Get$propertyname$($class$ instance)
{
return Get$propertyname$Delegate(instance);
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>