Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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; } } } }[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- NameSpaceEvent.cs
- securitycriticaldataClass.cs
- RectIndependentAnimationStorage.cs
- JavaScriptObjectDeserializer.cs
- InvalidWorkflowException.cs
- SerialPinChanges.cs
- FormsAuthenticationUser.cs
- Operand.cs
- RowUpdatedEventArgs.cs
- Solver.cs
- X509CertificateInitiatorServiceCredential.cs
- WaitHandle.cs
- isolationinterop.cs
- ManipulationDevice.cs
- Transform3DGroup.cs
- DataTableExtensions.cs
- MouseCaptureWithinProperty.cs
- IfJoinedCondition.cs
- BindingValueChangedEventArgs.cs
- SecurityContext.cs
- ClientRolePrincipal.cs
- KeyFrames.cs
- BuildProvider.cs
- XmlSchemaValidationException.cs
- SendingRequestEventArgs.cs
- RelatedEnd.cs
- DelegateSerializationHolder.cs
- Cloud.cs
- Stream.cs
- XmlSchemaSubstitutionGroup.cs
- MenuTracker.cs
- XPathNavigator.cs
- StyleCollection.cs
- MetadataException.cs
- UnlockCardRequest.cs
- InkCanvasSelection.cs
- SecurityKeyIdentifier.cs
- CatalogPart.cs
- TransformGroup.cs
- ClientCultureInfo.cs
- DependencySource.cs
- Function.cs
- WebPartMinimizeVerb.cs
- PreservationFileWriter.cs
- RenderContext.cs
- ItemContainerProviderWrapper.cs
- EntityProxyTypeInfo.cs
- WmlLabelAdapter.cs
- XmlLangPropertyAttribute.cs
- assemblycache.cs
- TypeTypeConverter.cs
- SortedDictionary.cs
- WebBrowserNavigatedEventHandler.cs
- StylusPoint.cs
- PageCatalogPart.cs
- WebPartTransformer.cs
- SqlDataSourceStatusEventArgs.cs
- UserThread.cs
- AssemblyBuilderData.cs
- ToolboxComponentsCreatedEventArgs.cs
- SqlUDTStorage.cs
- LinqDataSourceStatusEventArgs.cs
- SharedConnectionWorkflowTransactionService.cs
- DataPager.cs
- ActivityDesignerResources.cs
- XMLSchema.cs
- PropertyInfo.cs
- XmlSchemaSearchPattern.cs
- ZipIOCentralDirectoryBlock.cs
- PersonalizablePropertyEntry.cs
- ObjectItemAttributeAssemblyLoader.cs
- MsmqIntegrationSecurity.cs
- EntityViewContainer.cs
- BaseCollection.cs
- StateMachineDesignerPaint.cs
- ViewStateException.cs
- login.cs
- TableParaClient.cs
- DataReceivedEventArgs.cs
- PointLightBase.cs
- ScaleTransform.cs
- SchemaElementLookUpTable.cs
- SqlNotificationEventArgs.cs
- DataGridViewToolTip.cs
- DefaultProxySection.cs
- SqlGenerator.cs
- InfoCardPolicy.cs
- QueryParameter.cs
- PasswordDeriveBytes.cs
- ValueChangedEventManager.cs
- AssertUtility.cs
- AppSettingsSection.cs
- UnhandledExceptionEventArgs.cs
- MenuItemCollectionEditorDialog.cs
- DateTimeFormatInfo.cs
- AlignmentYValidation.cs
- IdentityModelDictionary.cs
- RoleExceptions.cs
- BuildProviderUtils.cs
- FamilyCollection.cs