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
- MetadataUtilsSmi.cs
- SingleTagSectionHandler.cs
- ContentHostHelper.cs
- HostingEnvironmentException.cs
- DirectoryInfo.cs
- WebPartAuthorizationEventArgs.cs
- RemotingConfigParser.cs
- PerformanceCounters.cs
- XmlDocumentFieldSchema.cs
- MemoryFailPoint.cs
- ExtentCqlBlock.cs
- ProtectedConfiguration.cs
- EnvelopeVersion.cs
- CodeVariableReferenceExpression.cs
- UpdateProgress.cs
- ObjectListGeneralPage.cs
- documentsequencetextpointer.cs
- ScriptingProfileServiceSection.cs
- ConfigurationLockCollection.cs
- newitemfactory.cs
- CodeExpressionStatement.cs
- FontUnitConverter.cs
- FusionWrap.cs
- ColumnCollection.cs
- SqlProcedureAttribute.cs
- GregorianCalendarHelper.cs
- DetailsViewModeEventArgs.cs
- CssTextWriter.cs
- ConnectionConsumerAttribute.cs
- FloaterParaClient.cs
- XmlLanguageConverter.cs
- PageThemeBuildProvider.cs
- AutomationPropertyInfo.cs
- GridItemProviderWrapper.cs
- MaskedTextBoxTextEditor.cs
- XPathExpr.cs
- LassoHelper.cs
- TemplateContainer.cs
- OpenTypeLayout.cs
- RegisteredDisposeScript.cs
- CodeAttachEventStatement.cs
- SplashScreenNativeMethods.cs
- WebPartEditorApplyVerb.cs
- UInt16Storage.cs
- SqlFactory.cs
- InvalidFilterCriteriaException.cs
- EntityClientCacheEntry.cs
- Vector3DCollectionValueSerializer.cs
- SoapWriter.cs
- ToggleButton.cs
- Msec.cs
- InternalException.cs
- GroupQuery.cs
- XamlGridLengthSerializer.cs
- CreatingCookieEventArgs.cs
- CommandLibraryHelper.cs
- CharacterBufferReference.cs
- TextUtf8RawTextWriter.cs
- bidPrivateBase.cs
- ComponentResourceKey.cs
- ObjectViewFactory.cs
- BindingList.cs
- DynamicResourceExtension.cs
- MenuItemCollection.cs
- AsyncCompletedEventArgs.cs
- GACMembershipCondition.cs
- AdRotatorDesigner.cs
- StringSorter.cs
- AxWrapperGen.cs
- PolicyFactory.cs
- WebPartTracker.cs
- BCryptHashAlgorithm.cs
- MouseWheelEventArgs.cs
- ListMarkerSourceInfo.cs
- ContentType.cs
- ToolStripItem.cs
- ToolboxComponentsCreatedEventArgs.cs
- COM2IPerPropertyBrowsingHandler.cs
- NativeMethods.cs
- TimersDescriptionAttribute.cs
- FormClosedEvent.cs
- WindowsScrollBar.cs
- DesignBindingPicker.cs
- LZCodec.cs
- RegularExpressionValidator.cs
- SignatureToken.cs
- SqlBulkCopyColumnMappingCollection.cs
- FlowDocumentReaderAutomationPeer.cs
- ArraySubsetEnumerator.cs
- ErrorRuntimeConfig.cs
- DbConnectionClosed.cs
- EventSinkActivityDesigner.cs
- TraceSection.cs
- SoapSchemaExporter.cs
- LicenseProviderAttribute.cs
- Int64AnimationUsingKeyFrames.cs
- IisTraceListener.cs
- DataSetMappper.cs
- Thickness.cs
- CryptoHandle.cs