/// <summary>
/// Daniel Balla's Weblog - Various posts
/// on .NET Development, ASP.NET, Agile,
/// TDD, Architecture, SQL and others.
/// </summary>
[Serializable]
class Blog<T> where T : ASP.NET, Ajax, WCF, WF, new()
{
}
Monday, October 02, 2006
Event code snippet
Indeed, most times you write the events at a time, maybe in a region and the trigger methods afterwards in another region; but then you do the same with local fields and properties, and yet the prop snippet comes in handy. Therefore I thought a simple event code snippet would be useful. You can download it here and then copy it to your Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#\ directory
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>event</Title>
<Shortcut>event</Shortcut>
<Description>Code snippet to created and document an event</Description>
<Author>Daniel Balla</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>event</ID>
<ToolTip>Event name</ToolTip>
<Default>MyEvent</Default>
</Literal>
<Literal>
<ID>eventArgs</ID>
<ToolTip>Event arguments type</ToolTip>
<Default>EventArgs</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[#region Event Handler $event$ ($eventArgs$)
/// <summary>
/// This event is fired when |
/// </summary>
public event EventHandler $event$;
#endregion
#region Event notification $event$
/// <summary>
/// Notifies the listeners of the $event$ event
/// </summary>
/// <param name="e">The argument to send to the listeners</param>
protected virtual void On$event$($eventArgs$ e) {
if($event$ != null) {
$event$(this,e);
}
}
#endregion$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>event</Title>
<Shortcut>event</Shortcut>
<Description>Code snippet to created and document an event</Description>
<Author>Daniel Balla</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>event</ID>
<ToolTip>Event name</ToolTip>
<Default>MyEvent</Default>
</Literal>
<Literal>
<ID>eventArgs</ID>
<ToolTip>Event arguments type</ToolTip>
<Default>EventArgs</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[#region Event Handler $event$ ($eventArgs$)
/// <summary>
/// This event is fired when |
/// </summary>
public event EventHandler $event$;
#endregion
#region Event notification $event$
/// <summary>
/// Notifies the listeners of the $event$ event
/// </summary>
/// <param name="e">The argument to send to the listeners</param>
protected virtual void On$event$($eventArgs$ e) {
if($event$ != null) {
$event$(this,e);
}
}
#endregion$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

0 Comments:
Post a Comment
<< Home