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; ////// [HostProtection(SharedState = true)] public sealed class EventHandlerList : IDisposable { ListEntry head; Component parent; ///Provides a simple list of delegates. This class cannot be inherited. ////// 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; } ////// 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); } } } ///Gets or sets the delegate for the specified key. ////// [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); } } ///[To be supplied.] ///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; } } ////// 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; } } } }[To be supplied.] ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EntityEntry.cs
- FileDialog.cs
- XmlChildNodes.cs
- ServiceModelStringsVersion1.cs
- HtmlInputHidden.cs
- FullTextBreakpoint.cs
- unsafenativemethodsother.cs
- Facet.cs
- GridItemCollection.cs
- StrongNameMembershipCondition.cs
- TextElementAutomationPeer.cs
- ReadOnlyHierarchicalDataSource.cs
- DrawingAttributesDefaultValueFactory.cs
- TargetPerspective.cs
- LoginView.cs
- ResourceWriter.cs
- DataTableMapping.cs
- X509ChainElement.cs
- ProxyHwnd.cs
- Int32CollectionValueSerializer.cs
- ToolStripItemImageRenderEventArgs.cs
- UnconditionalPolicy.cs
- SecureStringHasher.cs
- LongValidator.cs
- SqlConnectionStringBuilder.cs
- FontInfo.cs
- StdRegProviderWrapper.cs
- CircleHotSpot.cs
- SimpleRecyclingCache.cs
- AttributeParameterInfo.cs
- DiscreteKeyFrames.cs
- TypeUnloadedException.cs
- ClientConfigPaths.cs
- SystemDropShadowChrome.cs
- SweepDirectionValidation.cs
- ItemPager.cs
- DateTimePickerDesigner.cs
- Error.cs
- TreeViewCancelEvent.cs
- MultiByteCodec.cs
- WebServiceParameterData.cs
- ResourceType.cs
- StringExpressionSet.cs
- SiteMapProvider.cs
- EditorAttribute.cs
- SqlDependencyListener.cs
- TextElement.cs
- SystemWebCachingSectionGroup.cs
- ReflectionUtil.cs
- MimeFormImporter.cs
- OrderablePartitioner.cs
- _NestedMultipleAsyncResult.cs
- TableItemPattern.cs
- PageContentCollection.cs
- NumericUpDownAcceleration.cs
- NotSupportedException.cs
- HuffmanTree.cs
- UnionExpr.cs
- HttpConfigurationContext.cs
- unitconverter.cs
- TypeForwardedToAttribute.cs
- DiscardableAttribute.cs
- NetworkInformationPermission.cs
- SqlDependencyUtils.cs
- DbConnectionPoolOptions.cs
- JournalEntryStack.cs
- DataGridLinkButton.cs
- BuildProviderCollection.cs
- DataGridViewBand.cs
- Listen.cs
- CreateRefExpr.cs
- MarkupExtensionParser.cs
- DocumentDesigner.cs
- LoginName.cs
- CSharpCodeProvider.cs
- SimpleType.cs
- ScriptModule.cs
- Model3D.cs
- CurrentTimeZone.cs
- NamespaceQuery.cs
- _LocalDataStoreMgr.cs
- CharacterShapingProperties.cs
- ResourceReferenceKeyNotFoundException.cs
- LinkClickEvent.cs
- CopyOfAction.cs
- OpCodes.cs
- TextParagraph.cs
- RandomDelayQueuedSendsAsyncResult.cs
- SearchForVirtualItemEventArgs.cs
- WebPartConnectionsEventArgs.cs
- TabletDeviceInfo.cs
- GatewayDefinition.cs
- UserControlBuildProvider.cs
- XmlSchemaInclude.cs
- XhtmlBasicValidatorAdapter.cs
- ScopedKnownTypes.cs
- CursorConverter.cs
- RelatedImageListAttribute.cs
- BindingSource.cs
- DataRelationPropertyDescriptor.cs