Code:
/ FX-1434 / FX-1434 / 1.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
- WebBodyFormatMessageProperty.cs
- TextEditorMouse.cs
- RuntimeConfig.cs
- DataGridViewRowPostPaintEventArgs.cs
- ApplicationServicesHostFactory.cs
- FacetValueContainer.cs
- MaterialCollection.cs
- TextEndOfLine.cs
- HtmlElementCollection.cs
- XmlC14NWriter.cs
- FileUpload.cs
- IERequestCache.cs
- ProviderConnectionPointCollection.cs
- MimeFormatExtensions.cs
- OverrideMode.cs
- QilGenerator.cs
- Update.cs
- AutoSizeToolBoxItem.cs
- TypeDescriptionProviderAttribute.cs
- CompModSwitches.cs
- Add.cs
- tabpagecollectioneditor.cs
- ScrollItemPatternIdentifiers.cs
- FrameworkReadOnlyPropertyMetadata.cs
- ErrorRuntimeConfig.cs
- PointLight.cs
- RequestUriProcessor.cs
- UncommonField.cs
- DecimalConverter.cs
- ForwardPositionQuery.cs
- BindingOperations.cs
- SharedStream.cs
- NodeInfo.cs
- SqlProfileProvider.cs
- TransformerInfo.cs
- DocumentAutomationPeer.cs
- MailAddress.cs
- MissingManifestResourceException.cs
- HwndKeyboardInputProvider.cs
- CachedBitmap.cs
- TableDetailsRow.cs
- DrawingCollection.cs
- ParserContext.cs
- RemoteWebConfigurationHostStream.cs
- EdmConstants.cs
- RowCache.cs
- EnumerableWrapperWeakToStrong.cs
- BaseUriHelper.cs
- PerspectiveCamera.cs
- GlobalDataBindingHandler.cs
- ObjectListComponentEditor.cs
- FontDriver.cs
- TextDecorationCollection.cs
- TextServicesLoader.cs
- WorkflowInstanceProvider.cs
- KeyValueConfigurationCollection.cs
- XpsFilter.cs
- GridViewDeletedEventArgs.cs
- remotingproxy.cs
- DurableDispatcherAddressingFault.cs
- BuildProvider.cs
- SQLMoneyStorage.cs
- ConfigurationValue.cs
- DataSourceControlBuilder.cs
- DataServiceExpressionVisitor.cs
- xmlsaver.cs
- TextEditorLists.cs
- SHA512Managed.cs
- CheckBoxRenderer.cs
- WebPartManagerInternals.cs
- ConnectionManagementSection.cs
- DataPagerField.cs
- AuthStoreRoleProvider.cs
- InkSerializer.cs
- IPAddressCollection.cs
- SHA512.cs
- XmlSerializableWriter.cs
- ModuleBuilder.cs
- ExpressionBuilderContext.cs
- ITextView.cs
- Evaluator.cs
- CompositionAdorner.cs
- CacheMemory.cs
- WebControlsSection.cs
- BrowserCapabilitiesFactoryBase.cs
- DataGridAddNewRow.cs
- BmpBitmapEncoder.cs
- MDIControlStrip.cs
- TypeDescriptorContext.cs
- WorkflowDefinitionDispenser.cs
- WebOperationContext.cs
- SimpleType.cs
- Misc.cs
- SettingsContext.cs
- FloaterParaClient.cs
- HttpServerUtilityBase.cs
- Utils.cs
- ListViewDeleteEventArgs.cs
- UnsafeNativeMethods.cs
- ViewBox.cs