Code:
/ 4.0 / 4.0 / 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.] ///// 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
- EditorPart.cs
- SystemInfo.cs
- SqlCacheDependencyDatabaseCollection.cs
- VoiceChangeEventArgs.cs
- BindingValueChangedEventArgs.cs
- FileAuthorizationModule.cs
- StatusBar.cs
- XmlSchemaObjectCollection.cs
- WebPartEditorCancelVerb.cs
- XmlFormatExtensionAttribute.cs
- MiniConstructorInfo.cs
- XmlSchemaSimpleContentExtension.cs
- InfoCardCryptoHelper.cs
- EventManager.cs
- InvalidProgramException.cs
- Point3DIndependentAnimationStorage.cs
- DataGridViewDataConnection.cs
- CharacterBuffer.cs
- BinHexEncoder.cs
- InputQueue.cs
- RangeContentEnumerator.cs
- ConfigXmlAttribute.cs
- CompilerTypeWithParams.cs
- ComPlusInstanceProvider.cs
- EndSelectCardRequest.cs
- ExpandSegmentCollection.cs
- Scheduler.cs
- SwitchAttribute.cs
- CompareInfo.cs
- ObjectItemCollection.cs
- GroupStyle.cs
- CodePropertyReferenceExpression.cs
- ResourceDictionary.cs
- EntityTypeBase.cs
- VisualBasicExpressionConverter.cs
- MonikerUtility.cs
- MergePropertyDescriptor.cs
- XmlEntityReference.cs
- XmlUTF8TextWriter.cs
- IIS7UserPrincipal.cs
- CompilerGeneratedAttribute.cs
- MembershipValidatePasswordEventArgs.cs
- TriState.cs
- InternalPermissions.cs
- ButtonPopupAdapter.cs
- PrintPreviewControl.cs
- ResourceWriter.cs
- ProviderUtil.cs
- Tokenizer.cs
- CellRelation.cs
- WebPartCancelEventArgs.cs
- TableRow.cs
- WindowsAuthenticationEventArgs.cs
- ColumnCollection.cs
- HitTestParameters.cs
- DesignerToolboxInfo.cs
- SparseMemoryStream.cs
- ButtonPopupAdapter.cs
- XpsColorContext.cs
- Pair.cs
- DoubleAnimationUsingPath.cs
- TableDetailsCollection.cs
- ImageUrlEditor.cs
- OverflowException.cs
- MobilePage.cs
- RemotingConfiguration.cs
- MimeXmlImporter.cs
- ErrorProvider.cs
- HashMembershipCondition.cs
- ClientTargetCollection.cs
- DataGridTable.cs
- ValidatorCollection.cs
- GridViewColumnHeaderAutomationPeer.cs
- RectConverter.cs
- Quad.cs
- MethodExpr.cs
- BmpBitmapEncoder.cs
- Camera.cs
- DiagnosticEventProvider.cs
- Blend.cs
- ProcessModule.cs
- FlowNode.cs
- AsyncContentLoadedEventArgs.cs
- ImageMapEventArgs.cs
- CommonObjectSecurity.cs
- ErrorFormatter.cs
- DbMetaDataCollectionNames.cs
- DescriptionCreator.cs
- XamlFxTrace.cs
- _ListenerResponseStream.cs
- DataGridViewLinkCell.cs
- TextServicesCompartmentEventSink.cs
- CodeGroup.cs
- PageBuildProvider.cs
- TextServicesProperty.cs
- MailMessageEventArgs.cs
- ClientRuntimeConfig.cs
- WebEventTraceProvider.cs
- Stream.cs
- DataObjectMethodAttribute.cs