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
- ExceptionWrapper.cs
- GetRecipientListRequest.cs
- SpStreamWrapper.cs
- ImageKeyConverter.cs
- Span.cs
- TraceContextEventArgs.cs
- HostedTcpTransportManager.cs
- FormViewRow.cs
- ScrollBar.cs
- ILGenerator.cs
- HttpCapabilitiesEvaluator.cs
- XmlSignificantWhitespace.cs
- PropertyFilterAttribute.cs
- AudienceUriMode.cs
- ErrorEventArgs.cs
- RotateTransform.cs
- DoubleLinkListEnumerator.cs
- StorageModelBuildProvider.cs
- InternalDuplexChannelListener.cs
- TextParaClient.cs
- ListChunk.cs
- XmlUTF8TextWriter.cs
- StateMachineAction.cs
- RawStylusInputReport.cs
- ConfigurationPropertyAttribute.cs
- TimeSpanSecondsConverter.cs
- TriState.cs
- BmpBitmapEncoder.cs
- HostProtectionPermission.cs
- EventListener.cs
- Size.cs
- DataGridViewCheckBoxCell.cs
- HiddenFieldPageStatePersister.cs
- InternalSafeNativeMethods.cs
- BitmapCodecInfoInternal.cs
- OutputScopeManager.cs
- XhtmlTextWriter.cs
- InputBinder.cs
- BinaryFormatterSinks.cs
- SystemUnicastIPAddressInformation.cs
- Query.cs
- WindowClosedEventArgs.cs
- DropShadowEffect.cs
- UserControlCodeDomTreeGenerator.cs
- RemotingConfigParser.cs
- WebPartEditorCancelVerb.cs
- ELinqQueryState.cs
- ProjectionCamera.cs
- BackStopAuthenticationModule.cs
- DefinitionBase.cs
- FormsAuthenticationModule.cs
- XmlValidatingReaderImpl.cs
- WSFederationHttpBinding.cs
- PresentationAppDomainManager.cs
- safesecurityhelperavalon.cs
- Opcode.cs
- DbConnectionHelper.cs
- StringDictionary.cs
- UnsignedPublishLicense.cs
- KeyInstance.cs
- ModifiableIteratorCollection.cs
- URLIdentityPermission.cs
- EventLogPermission.cs
- XhtmlBasicListAdapter.cs
- PrintPreviewGraphics.cs
- __Filters.cs
- SourceElementsCollection.cs
- ConfigXmlCDataSection.cs
- HttpRawResponse.cs
- DeviceSpecificDialogCachedState.cs
- VectorAnimationUsingKeyFrames.cs
- UnsignedPublishLicense.cs
- CapiHashAlgorithm.cs
- DNS.cs
- BamlResourceSerializer.cs
- ColorTranslator.cs
- Privilege.cs
- URLIdentityPermission.cs
- SystemTcpStatistics.cs
- PrintDocument.cs
- CancelEventArgs.cs
- ReflectionUtil.cs
- SupportingTokenParameters.cs
- HttpRequestBase.cs
- PanningMessageFilter.cs
- DateTimeFormatInfoScanner.cs
- CodeBinaryOperatorExpression.cs
- MarkerProperties.cs
- TextTabProperties.cs
- ToolStripCustomTypeDescriptor.cs
- Transform3D.cs
- MultiAsyncResult.cs
- FieldBuilder.cs
- QilFactory.cs
- OdbcFactory.cs
- GridItemProviderWrapper.cs
- EntityContainerAssociationSetEnd.cs
- DataGridRowsPresenter.cs
- SQLByte.cs
- ShellProvider.cs