Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / ComponentModel / EventHandlerList.cs / 1305376 / 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; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AsyncCompletedEventArgs.cs
- MultipleCopiesCollection.cs
- ApplicationHost.cs
- XhtmlBasicImageAdapter.cs
- DynamicMethod.cs
- FileUtil.cs
- WebException.cs
- PenThreadPool.cs
- TableItemPattern.cs
- WmlControlAdapter.cs
- AvTraceDetails.cs
- TreeBuilderXamlTranslator.cs
- MasterPageCodeDomTreeGenerator.cs
- SafeNativeMethods.cs
- FormViewDeletedEventArgs.cs
- UrlPropertyAttribute.cs
- LoadItemsEventArgs.cs
- EventLogSession.cs
- TextRunCacheImp.cs
- FontSourceCollection.cs
- FontStyle.cs
- ParameterCollection.cs
- XhtmlTextWriter.cs
- EventManager.cs
- BindingListCollectionView.cs
- QueueProcessor.cs
- TabletDevice.cs
- Int16Animation.cs
- ExceptionUtil.cs
- UrlPath.cs
- AutomationEvent.cs
- HTTPNotFoundHandler.cs
- VirtualPath.cs
- EntityDataSourceMemberPath.cs
- RecordBuilder.cs
- MarginsConverter.cs
- SchemaDeclBase.cs
- IndexOutOfRangeException.cs
- TreeViewItem.cs
- OptimalTextSource.cs
- returneventsaver.cs
- DynamicDataManager.cs
- CollectionEditorDialog.cs
- JpegBitmapEncoder.cs
- AccessKeyManager.cs
- DataFieldConverter.cs
- SmiConnection.cs
- StateManagedCollection.cs
- CoordinationService.cs
- PropertyGroupDescription.cs
- NodeFunctions.cs
- DeviceContext.cs
- EditorAttribute.cs
- RightNameExpirationInfoPair.cs
- WebPartDisplayMode.cs
- JsonServiceDocumentSerializer.cs
- NavigationWindowAutomationPeer.cs
- BitmapImage.cs
- XpsFilter.cs
- ItemCheckedEvent.cs
- BindingCollection.cs
- Constraint.cs
- SystemWebCachingSectionGroup.cs
- _AcceptOverlappedAsyncResult.cs
- SkewTransform.cs
- HttpCachePolicy.cs
- AtomEntry.cs
- RSAProtectedConfigurationProvider.cs
- Ops.cs
- CngKey.cs
- XmlIlGenerator.cs
- CustomPopupPlacement.cs
- WebPartConnectionsEventArgs.cs
- WindowsGraphicsWrapper.cs
- SecurityCriticalDataForSet.cs
- LocationUpdates.cs
- EntityTypeEmitter.cs
- Int32Rect.cs
- ScrollBar.cs
- DateTimeOffsetStorage.cs
- Assert.cs
- DropDownButton.cs
- ReachIDocumentPaginatorSerializerAsync.cs
- Events.cs
- Hex.cs
- ModelItemImpl.cs
- DefaultValueAttribute.cs
- XmlNodeComparer.cs
- Decorator.cs
- ModelItemDictionaryImpl.cs
- SecurityNegotiationException.cs
- ShapeTypeface.cs
- XmlSignatureProperties.cs
- PageWrapper.cs
- PropertyValueChangedEvent.cs
- SQLCharsStorage.cs
- HtmlInputReset.cs
- PointHitTestResult.cs
- DataControlButton.cs
- WindowCollection.cs