﻿<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>Component Event Member</Title>
			<Shortcut>eventc</Shortcut>
			<Description>Creates the canonical event member declaration and corresponding method for invocation  for a class that derives from System.ComponentModel.Component.  EventHandler is used as the delegate.  The code produced by this snippet is thread-safe.</Description>
			<Author>Dave Sexton</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
				<SnippetType>SurroundsWith</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal Editable="true">
					<ID>handler</ID>
					<Default>EventHandler</Default>
					<Type>System.Delegate</Type>
				</Literal>
				<Literal Editable="true">
					<ID>args</ID>
					<Default>EventArgs</Default>
					<Type>System.EventArgs</Type>
				</Literal>				
				<Literal Editable="true">
					<ID>name</ID>
					<Default>TextChanged</Default>
					<Type>System.String</Type>
				</Literal>
				<Literal Editable="true">
					<ID>summary</ID>
					<Default>Event raised after the &lt;see cref="Text" /&gt; property value has changed.</Default>
					<Type>System.String</Type>
				</Literal>
				<Literal Editable="true">
					<ID>desc</ID>
					<Default>Event raised after the Text property value has changed.</Default>
					<Type>System.String</Type>
				</Literal>
				<Literal Editable="true">
					<ID>cat</ID>
					<Default>Property Changed</Default>
					<Type>System.String</Type>
				</Literal>
			</Declarations>
			<Code Language="csharp">
				<![CDATA[private readonly object $name$Event = new object();
		$selected$ $end$
		/// <summary>
		/// $summary$
		/// </summary>
		[Category("$cat$")]
		[Description("$desc$")]
		public event $handler$ $name$
		{
			add
			{
				lock ($name$Event)
				{
					Events.AddHandler($name$Event, value);
				}
			}
			remove
			{
				lock ($name$Event)
				{
					Events.RemoveHandler($name$Event, value);
				}
			}
		}
		
		/// <summary>
		/// Raises the <see cref="$name$" /> event.
		/// </summary>
		/// <param name="e"><see cref="$args$" /> object that provides the arguments for the event.</param>
		protected virtual void On$name$($args$ e)
		{
			$handler$ handler = null;

			lock ($name$Event)
			{
				handler = ($handler$) Events[$name$Event];
			}

			if (handler != null)
				handler(this, e);
		}]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>