Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / System / ComponentModel / EventHandlerList.cs / 1 / EventHandlerList.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.ComponentModel {
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Permissions;
///
/// Provides a simple list of delegates. This class cannot be inherited.
///
[HostProtection(SharedState = true)]
public sealed class EventHandlerList : IDisposable {
ListEntry head;
Component parent;
///
/// Creates a new event handler list.
///
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
public EventHandlerList()
{
}
///
/// Creates a new event handler list. The parent component is used to check the component's
/// CanRaiseEvents property.
///
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
internal EventHandlerList(Component parent)
{
this.parent = parent;
}
///
/// Gets or sets the delegate for the specified key.
///
public Delegate this[object key] {
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
get {
ListEntry e = null;
if (parent == null || parent.CanRaiseEventsInternal)
{
e = Find(key);
}
if (e != null) {
return e.handler;
}
else {
return null;
}
}
set {
ListEntry e = Find(key);
if (e != null) {
e.handler = value;
}
else {
head = new ListEntry(key, value, head);
}
}
}
///
/// [To be supplied.]
///
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
public void AddHandler(object key, Delegate value) {
ListEntry e = Find(key);
if (e != null) {
e.handler = Delegate.Combine(e.handler, value);
}
else {
head = new ListEntry(key, value, head);
}
}
/// allows you to add a list of events to this list
public void AddHandlers(EventHandlerList listToAddFrom) {
ListEntry currentListEntry = listToAddFrom.head;
while (currentListEntry != null) {
AddHandler(currentListEntry.key, currentListEntry.handler);
currentListEntry = currentListEntry.next;
}
}
///
/// [To be supplied.]
///
public void Dispose() {
head = null;
}
private ListEntry Find(object key) {
ListEntry found = head;
while (found != null) {
if (found.key == key) {
break;
}
found = found.next;
}
return found;
}
///
/// [To be supplied.]
///
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
public void RemoveHandler(object key, Delegate value) {
ListEntry e = Find(key);
if (e != null) {
e.handler = Delegate.Remove(e.handler, value);
}
// else... no error for removal of non-existant delegate
//
}
private sealed class ListEntry {
internal ListEntry next;
internal object key;
internal Delegate handler;
public ListEntry(object key, Delegate handler, ListEntry next) {
this.next = next;
this.key = key;
this.handler = handler;
}
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SimpleType.cs
- DataGridViewRowCollection.cs
- CaseInsensitiveOrdinalStringComparer.cs
- AttributeProviderAttribute.cs
- Rotation3DKeyFrameCollection.cs
- Itemizer.cs
- BitmapDecoder.cs
- DurableOperationContext.cs
- WebPartChrome.cs
- ObjectKeyFrameCollection.cs
- BindStream.cs
- QueryActivatableWorkflowsCommand.cs
- ReadOnlyNameValueCollection.cs
- HtmlControlPersistable.cs
- OperandQuery.cs
- AsmxEndpointPickerExtension.cs
- ByteAnimation.cs
- WebPartUserCapability.cs
- Substitution.cs
- StatusBarItemAutomationPeer.cs
- Clause.cs
- BitmapEffectrendercontext.cs
- DataGridHelper.cs
- UnsafeNativeMethods.cs
- LayoutInformation.cs
- ChangeBlockUndoRecord.cs
- UIntPtr.cs
- ParentQuery.cs
- ListViewTableCell.cs
- TreeViewBindingsEditorForm.cs
- SizeIndependentAnimationStorage.cs
- HtmlControl.cs
- DataTableMappingCollection.cs
- SQLMembershipProvider.cs
- ProtocolsConfigurationEntry.cs
- InputLanguageCollection.cs
- WS2007FederationHttpBinding.cs
- ImageAttributes.cs
- PolyBezierSegmentFigureLogic.cs
- CancelEventArgs.cs
- DockPattern.cs
- ContentOperations.cs
- SymbolEqualComparer.cs
- ConfigurationSchemaErrors.cs
- BeginEvent.cs
- MethodRental.cs
- login.cs
- GridViewColumn.cs
- SequentialActivityDesigner.cs
- CompositeDuplexBindingElement.cs
- EventLogEntry.cs
- SelectQueryOperator.cs
- ViewLoader.cs
- ObjectDataSourceSelectingEventArgs.cs
- TrustManagerMoreInformation.cs
- ColumnReorderedEventArgs.cs
- mda.cs
- Stack.cs
- XmlTextEncoder.cs
- XmlILIndex.cs
- Int32Storage.cs
- CodePageUtils.cs
- WindowsListViewItemCheckBox.cs
- DBNull.cs
- DbConnectionPoolGroup.cs
- XmlILCommand.cs
- InputLanguageCollection.cs
- FullTextBreakpoint.cs
- WinFormsUtils.cs
- QilChoice.cs
- RectAnimation.cs
- TransformValueSerializer.cs
- PropertyDescriptorGridEntry.cs
- Paragraph.cs
- SqlBooleanizer.cs
- ActivityTypeResolver.xaml.cs
- EventProxy.cs
- InkCanvasSelection.cs
- SqlConnectionFactory.cs
- CopyNodeSetAction.cs
- EraserBehavior.cs
- DuplexChannelFactory.cs
- DataTableTypeConverter.cs
- StorageEndPropertyMapping.cs
- Pts.cs
- SiteMapDataSourceView.cs
- SqlConnectionHelper.cs
- VisualStyleInformation.cs
- Compiler.cs
- MSAAEventDispatcher.cs
- ResizeGrip.cs
- Base64Decoder.cs
- DataGridBoolColumn.cs
- Speller.cs
- Soap12ProtocolReflector.cs
- HashCryptoHandle.cs
- PointCollection.cs
- METAHEADER.cs
- XPathNodeHelper.cs
- WebScriptMetadataMessageEncodingBindingElement.cs