download EventHandlerList.cs
Language: C#
License: GPL
Copyright: (C) 2002 Southern Storm Software, Pty Ltd.
LOC: 101
Project Info
gpe
Server: HandHelds
Type: cvs
...tlib\System\ComponentModel\
   AmbientValueAttribute.cs
   ArrayConverter.cs
   AsyncCompletedEventArgs.cs
   ...ompletedEventHandler.cs
   AttributeCollection.cs
   BaseNumberConverter.cs
   BindableAttribute.cs
   BindableSupport.cs
   BooleanConverter.cs
   BrowsableAttribute.cs
   ByteConverter.cs
   CancelEventArgs.cs
   CancelEventHandler.cs
   CategoryAttribute.cs
   CharConverter.cs
   CollectionChangeAction.cs
   ...ctionChangeEventArgs.cs
   ...onChangeEventHandler.cs
   CollectionConverter.cs
   Component.cs
   ComponentCollection.cs
   ComponentConverter.cs
   ComponentEditor.cs
   ...onentResourceManager.cs
   Container.cs
   CultureInfoConverter.cs
   DateTimeConverter.cs
   DecimalConverter.cs
   DefaultEventAttribute.cs
   ...ultPropertyAttribute.cs
   DefaultValueAttribute.cs
   DescriptionAttribute.cs
   DesignerAttribute.cs
   ...nerCategoryAttribute.cs
   ...ializationVisibility.cs
   ...nVisibilityAttribute.cs
   DesignOnlyAttribute.cs
   ...TimeVisibleAttribute.cs
   DoubleConverter.cs
   EditorAttribute.cs
   ...orBrowsableAttribute.cs
   EditorBrowsableState.cs
   EnumConverter.cs
   EventDescriptor.cs
   ...DescriptorCollection.cs
   EventHandlerList.cs
   ...dableObjectConverter.cs
   ...dedPropertyAttribute.cs
   GuidConverter.cs
   IBindingList.cs
   ...iveDescriptorHandler.cs
   IComponent.cs
   IContainer.cs
   ICustomTypeDescriptor.cs
   IDataErrorInfo.cs
   IEditableObject.cs
   IExtenderProvider.cs
   IListSource.cs
   ...tableObjectAttribute.cs
   InheritanceAttribute.cs
   InheritanceLevel.cs
   InstallerTypeAttribute.cs
   Int16Converter.cs
   Int32Converter.cs
   Int64Converter.cs
   ...numArgumentException.cs
   ISite.cs
   ISupportInitialize.cs
   ISynchronizeInvoke.cs
   ITypeDescriptorContext.cs
   ITypedList.cs
   License.cs
   LicenseContext.cs
   LicenseException.cs
   LicenseManager.cs
   LicenseProvider.cs
   ...nseProviderAttribute.cs
   LicenseUsageMode.cs
   LicFileLicenseProvider.cs
   ListBindableAttribute.cs
   ListChangedEventArgs.cs
   ListChangedEventHandler.cs
   ListChangedType.cs
   ListSortDirection.cs
   LocalizableAttribute.cs
   MarshalByValueComponent.cs
   MemberDescriptor.cs
   ...blePropertyAttribute.cs
   ...entPropertyAttribute.cs
   ...ropertyNameAttribute.cs
   ...ressChangedEventArgs.cs
   ...sChangedEventHandler.cs
   ...ertyChangedEventArgs.cs
   ...yChangedEventHandler.cs
   PropertyDescriptor.cs
   ...DescriptorCollection.cs
   PropertyTabAttribute.cs
   PropertyTabScope.cs
   ...idePropertyAttribute.cs
   ReadOnlyAttribute.cs
   ...onfigurableAttribute.cs
   ReferenceConverter.cs
   RefreshEventArgs.cs
   RefreshEventHandler.cs
   RefreshProperties.cs
   ...hPropertiesAttribute.cs
   RunInstallerAttribute.cs
   SByteConverter.cs
   SingleConverter.cs
   StringConverter.cs
   SyntaxCheck.cs
   TimeSpanConverter.cs
   ToolboxItemAttribute.cs
   ...xItemFilterAttribute.cs
   ToolboxItemFilterType.cs
   TypeConverter.cs
   TypeConverterAttribute.cs
   TypeDescriptor.cs
   TypeListConverter.cs
   UInt16Converter.cs
   UInt32Converter.cs
   UInt64Converter.cs
   WarningException.cs
   Win32Exception.cs

/*
 * EventHandlerList.cs - Implementation of the
 *		"System.ComponentModule.EventHandlerList" class.
 *
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;

public sealed class EventHandlerList : IDisposable
{
	// Internal storage for the list.
	private EventHandlerEntry list;

	// Constructor.
	public EventHandlerList()
			{
				list = null;
			}

	// Get or set a delegate on this list, by key.
	public Delegate this[Object key]
			{
				get
				{
					EventHandlerEntry entry = list;
					while(entry != null)
					{
						if(entry.key == key)
						{
							return entry.value;
						}
						entry = entry.next;
					}
					return null;
				}
				set
				{
					EventHandlerEntry entry = list;
					while(entry != null)
					{
						if(entry.key == key)
						{
							entry.value = value;
							return;
						}
						entry = entry.next;
					}
					list = new EventHandlerEntry(key, value, list);
				}
			}

	// Add a handler to this list.
	public void AddHandler(Object key, Delegate value)
			{
				EventHandlerEntry entry = list;
				while(entry != null)
				{
					if(entry.key == key)
					{
						entry.value = Delegate.Combine(entry.value, value);
						return;
					}
					entry = entry.next;
				}
				list = new EventHandlerEntry(key, value, list);
			}

	// Remove a handler from this list.
	public void RemoveHandler(Object key, Delegate value)
			{
				EventHandlerEntry entry = list;
				EventHandlerEntry prev = null;
				while(entry != null)
				{
					if(entry.key == key)
					{
						entry.value = Delegate.Remove(entry.value, value);
						if(entry.value == null)
						{
							if(prev != null)
							{
								prev.next = entry.next;
							}
							else
							{
								list = entry.next;
							}
						}
						return;
					}
					prev = entry;
					entry = entry.next;
				}
			}

	// Implement the IDisposable interface.
	public void Dispose()
			{
				list = null;
			}

	// Information that is stored for an event handler entry.
	private class EventHandlerEntry
	{
		// Internal state.
		public Object key;
		public Delegate value;
		public EventHandlerEntry next;

		// Constructor.
		public EventHandlerEntry(Object key, Delegate value,
								 EventHandlerEntry next)
				{
					this.key = key;
					this.value = value;
					this.next = next;
				}

	}; // class EventHandlerEntry

}; // class EventHandlerList

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us