Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- FontWeights.cs
- RegionInfo.cs
- Roles.cs
- EventSinkHelperWriter.cs
- TextFormatterContext.cs
- TrackingMemoryStreamFactory.cs
- PeerNearMe.cs
- MetadataItem.cs
- XmlDataDocument.cs
- AggregateNode.cs
- ApplicationSettingsBase.cs
- HeaderPanel.cs
- SoapHeaders.cs
- DataConnectionHelper.cs
- PenCursorManager.cs
- DataListItemEventArgs.cs
- AssemblySettingAttributes.cs
- OutputCacheSettingsSection.cs
- StylusPointDescription.cs
- TextFormatterImp.cs
- SqlDependencyUtils.cs
- ToolStripContainer.cs
- NullReferenceException.cs
- FacetEnabledSchemaElement.cs
- SchemaMapping.cs
- ImageMapEventArgs.cs
- BinaryObjectWriter.cs
- AssertSection.cs
- login.cs
- ReadOnlyDictionary.cs
- DesignOnlyAttribute.cs
- DrawListViewColumnHeaderEventArgs.cs
- HttpPostServerProtocol.cs
- ToolBarPanel.cs
- XMLDiffLoader.cs
- DataGrid.cs
- CachedBitmap.cs
- DynamicPropertyHolder.cs
- InteropEnvironment.cs
- EntityType.cs
- MultiPropertyDescriptorGridEntry.cs
- CodePageUtils.cs
- SolidColorBrush.cs
- DrawingCollection.cs
- xmlsaver.cs
- BreakRecordTable.cs
- SharedConnectionInfo.cs
- SupportsEventValidationAttribute.cs
- SystemResourceHost.cs
- WebPartsSection.cs
- KeyConstraint.cs
- XmlTypeAttribute.cs
- WorkflowTimerService.cs
- contentDescriptor.cs
- DictionaryEditChange.cs
- WebPartDeleteVerb.cs
- MatrixAnimationBase.cs
- MDIWindowDialog.cs
- MetadataItemEmitter.cs
- WebBrowserDesigner.cs
- Util.cs
- WsatServiceAddress.cs
- CustomAttributeSerializer.cs
- Dictionary.cs
- StorageMappingFragment.cs
- RectangleHotSpot.cs
- DoubleAnimationUsingKeyFrames.cs
- EntityCommand.cs
- GlyphRun.cs
- TemplateManager.cs
- EntityDataSourceContainerNameItem.cs
- WebPartRestoreVerb.cs
- Stack.cs
- Base64Stream.cs
- XPathNodeIterator.cs
- SafeHandles.cs
- DelimitedListTraceListener.cs
- xdrvalidator.cs
- DocumentXPathNavigator.cs
- SmtpDigestAuthenticationModule.cs
- DecoderReplacementFallback.cs
- TextEditorDragDrop.cs
- Parameter.cs
- DataServiceException.cs
- SerializationObjectManager.cs
- DataGridViewComboBoxCell.cs
- CaretElement.cs
- Environment.cs
- coordinatorscratchpad.cs
- HttpWebRequest.cs
- MimeWriter.cs
- BaseResourcesBuildProvider.cs
- HttpCachePolicyElement.cs
- QuerySettings.cs
- HostedHttpContext.cs
- ConcatQueryOperator.cs
- TextTabProperties.cs
- XmlValidatingReaderImpl.cs
- CryptoHelper.cs
- MailFileEditor.cs