Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7473


Ignore:
Timestamp:
02/16/12 08:21:43 (12 years ago)
Author:
abeham
Message:

#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.

Location:
trunk/tools/HL3Snippets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/HL3Snippets/HL3.DefineEvent.snippet

    r5036 r7473  
    2020          </Function>
    2121        </Literal>
     22        <Literal Editable="true">
     23          <ID>Modifier</ID>
     24          <ToolTip>Visibility modifier</ToolTip>
     25          <Default>protected virtual</Default>
     26          <Function>
     27          </Function>
     28        </Literal>
    2229      </Declarations>
    2330      <Code Language="csharp"><![CDATA[public event EventHandler $EventName$;
    24 
    25 protected virtual void On$EventName$() {
    26   EventHandler handler = $EventName$;
    27   if (handler != null)
    28     handler(this, EventArgs.Empty);
     31$Modifier$ void On$EventName$() {
     32  var handler = $EventName$;
     33  if (handler != null) handler(this, EventArgs.Empty);
    2934}]]></Code>
    3035    </Snippet>
  • trunk/tools/HL3Snippets/HL3.DefineGenericEvent.snippet

    r5061 r7473  
    3232          </Function>
    3333        </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>
    3441      </Declarations>
    3542      <Code Language="csharp"><![CDATA[public event EventHandler<EventArgs<$ArgsType$>> $EventName$;
    36 
    37 protected virtual void On$EventName$($ArgsType$ args) {
    38   EventHandler<EventArgs<$ArgsType$>> handler = $EventName$;
    39   if (handler != null)
    40     handler(this, new EventArgs<$ArgsType$>(args));
     43$Modifier$ void On$EventName$($ArgsType$ args) {
     44  var handler = $EventName$;
     45  if (handler != null) handler(this, new EventArgs<$ArgsType$>(args));
    4146}]]></Code>
    4247    </Snippet>
Note: See TracChangeset for help on using the changeset viewer.