Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //[To be supplied.] ///// 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
- CodeRemoveEventStatement.cs
- MetabaseSettingsIis7.cs
- GB18030Encoding.cs
- RuleRefElement.cs
- ContractCodeDomInfo.cs
- WindowsUpDown.cs
- ConnectionManager.cs
- MsmqReceiveParameters.cs
- ToolBarPanel.cs
- XmlReader.cs
- LedgerEntry.cs
- WebZone.cs
- ObjectContext.cs
- TrackingProfile.cs
- PageTheme.cs
- SafeCryptoHandles.cs
- _HeaderInfoTable.cs
- SocketException.cs
- QueryContinueDragEventArgs.cs
- WebPartDeleteVerb.cs
- SystemFonts.cs
- StringAnimationBase.cs
- figurelength.cs
- TraceListeners.cs
- FormViewModeEventArgs.cs
- PrivilegeNotHeldException.cs
- SessionStateContainer.cs
- ManagedCodeMarkers.cs
- EventLogException.cs
- AnonymousIdentificationSection.cs
- CqlParserHelpers.cs
- DataTableExtensions.cs
- PeerPresenceInfo.cs
- ViewStateModeByIdAttribute.cs
- Durable.cs
- PrintPreviewDialog.cs
- InternalDuplexBindingElement.cs
- SecurityContext.cs
- GeneralTransformGroup.cs
- PropertySourceInfo.cs
- ThreadAbortException.cs
- DataGridViewSelectedCellCollection.cs
- ColumnMapCopier.cs
- RuleRefElement.cs
- PersonalizableTypeEntry.cs
- Hashtable.cs
- UrlMapping.cs
- ReaderWriterLockWrapper.cs
- _RegBlobWebProxyDataBuilder.cs
- ToolStripPanelRenderEventArgs.cs
- XmlSchemaAll.cs
- DynamicField.cs
- EditorBrowsableAttribute.cs
- GridView.cs
- FontUnit.cs
- HiddenFieldDesigner.cs
- SortFieldComparer.cs
- BooleanProjectedSlot.cs
- DefaultObjectMappingItemCollection.cs
- TextContainerChangeEventArgs.cs
- ToolStripGrip.cs
- RegexReplacement.cs
- FieldAccessException.cs
- DescriptionAttribute.cs
- DataServiceRequest.cs
- XamlWriter.cs
- Asn1IntegerConverter.cs
- ProfileService.cs
- ButtonChrome.cs
- OleDbParameter.cs
- WorkflowValidationFailedException.cs
- RootProfilePropertySettingsCollection.cs
- RegistrationServices.cs
- ArgumentReference.cs
- GroupBox.cs
- ScriptResourceMapping.cs
- MarkupCompilePass2.cs
- PerformanceCounterManager.cs
- SectionInformation.cs
- HtmlEmptyTagControlBuilder.cs
- NativeCompoundFileAPIs.cs
- AspNetHostingPermission.cs
- PackageDigitalSignature.cs
- OperatingSystemVersionCheck.cs
- SiteMapPath.cs
- TypeDescriptionProviderAttribute.cs
- SchemaCollectionPreprocessor.cs
- ObjectNavigationPropertyMapping.cs
- MultiBinding.cs
- PageTheme.cs
- ProtocolElementCollection.cs
- HttpModuleActionCollection.cs
- MDIClient.cs
- XPathNavigatorReader.cs
- SecurityRuntime.cs
- BitHelper.cs
- PageTrueTypeFont.cs
- Vector3D.cs
- ProfilePropertyNameValidator.cs
- XamlWriter.cs