Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 C#2.0: create event and handler with args
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Uniwares
Tomato Guru

Portugal
2321 Posts

Posted - Jun 27 2008 :  11:21:12 AM  Show Profile  Reply with Quote
Another snippet to create an event with its own event argument.
It requires three snippet parameter: the event name (e.g.: DownloadCompleted, ActionStarted, etc.), the parameter type and the parameter name (which is also used to create a property in the event args)

It will create the delegate, the event, the eventarg class and two methods to fire the event.


#region Event $EventName$

/// <summary>
/// Event Arguments for $EventName$
/// </summary>
public class $EventName$EventArgs : EventArgs
{
	$ParameterType$ _$EventParameter$;

	public $EventName$EventArgs($ParameterType$ $EventParameter$)
	{
		this._$EventParameter$ = $EventParameter$;
	}

	public $ParameterType$ $EventParameter$
	{
		get { return _$EventParameter$; }
	}
}

public event System.EventHandler<$EventName$EventArgs> $EventName$;

public delegate void $EventName$Handler(object sender, $EventName$EventArgs e); 

/// <summary>
/// Raise the $EventName$ Event
/// </summary>
private void On$EventName$($EventName$EventArgs e)
{
	if($EventName$ != null)
	{
		$EventName$(this, e);
	}
}

/// <summary>
/// Raise the $EventName$ Event
/// </summary>
private void On$EventName$($ParameterType$ e)
{
	On$EventName$(new $EventName$EventArgs(e));
}

#endregion

Edited by - Uniwares on Jun 27 2008 11:21:46 AM
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000