Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/HL3Snippets/HL3.DefineGenericEvent.snippet @ 13765

Last change on this file since 13765 was 7473, checked in by abeham, 13 years ago

#1722: Updated event snippets to allow modifier to be set (in sealed classes you'll want to change it to private instead of protected virtual (which is the default). Also using "var" instead of the concrete class name as type for the handler variable and compacted code.

File size: 1.6 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
3  <CodeSnippet Format="1.0.0">
4    <Header>
5      <SnippetTypes>
6        <SnippetType>Expansion</SnippetType>
7      </SnippetTypes>
8      <Title>HL3.DefineGenericEvent</Title>
9      <Author>Erik Pitzer</Author>
10      <Description>Defines a generic events an a corresponing firing method.</Description>
11      <Shortcut>hl3DefineGenericEvent</Shortcut>
12    </Header>
13    <Snippet>
14      <Imports>
15        <Import>
16          <Namespace>HeuristicLab.Common</Namespace>
17        </Import>
18      </Imports>
19      <Declarations>
20        <Literal Editable="true">
21          <ID>ArgsType</ID>
22          <ToolTip>ArgsType</ToolTip>
23          <Default>ArgsType</Default>
24          <Function>
25          </Function>
26        </Literal>
27        <Literal Editable="true">
28          <ID>EventName</ID>
29          <ToolTip>EventName</ToolTip>
30          <Default>EventName</Default>
31          <Function>
32          </Function>
33        </Literal>
34        <Literal Editable="true">
35          <ID>Modifier</ID>
36          <ToolTip>Visibility modifier</ToolTip>
37          <Default>protected virtual</Default>
38          <Function>
39          </Function>
40        </Literal>
41      </Declarations>
42      <Code Language="csharp"><![CDATA[public event EventHandler<EventArgs<$ArgsType$>> $EventName$;
43$Modifier$ void On$EventName$($ArgsType$ args) {
44  var handler = $EventName$;
45  if (handler != null) handler(this, new EventArgs<$ArgsType$>(args));
46}]]></Code>
47    </Snippet>
48  </CodeSnippet>
49</CodeSnippets>
Note: See TracBrowser for help on using the repository browser.