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
- DispatchProxy.cs
- FilteredAttributeCollection.cs
- SystemSounds.cs
- RelationHandler.cs
- Repeater.cs
- SiteMapNodeItemEventArgs.cs
- BeginEvent.cs
- Debug.cs
- DataMemberFieldEditor.cs
- TemplatedMailWebEventProvider.cs
- NavigationWindowAutomationPeer.cs
- InputBindingCollection.cs
- DateTimePickerDesigner.cs
- AttributeTableBuilder.cs
- ConsumerConnectionPointCollection.cs
- BindToObject.cs
- ClientConfigPaths.cs
- SafeProcessHandle.cs
- SafeRightsManagementSessionHandle.cs
- SqlRowUpdatedEvent.cs
- DynamicHyperLink.cs
- MultidimensionalArrayItemReference.cs
- DeploymentSection.cs
- DelegateSerializationHolder.cs
- CardSpacePolicyElement.cs
- BuildProvider.cs
- BindingValueChangedEventArgs.cs
- SystemDropShadowChrome.cs
- ClientFormsAuthenticationMembershipProvider.cs
- ExtensionQuery.cs
- XamlInt32CollectionSerializer.cs
- Deserializer.cs
- LocalValueEnumerator.cs
- Exception.cs
- VarRefManager.cs
- Token.cs
- StandardTransformFactory.cs
- LineMetrics.cs
- RedirectionProxy.cs
- NullableFloatSumAggregationOperator.cs
- Events.cs
- DocumentAutomationPeer.cs
- EmptyEnumerator.cs
- UnionExpr.cs
- TargetControlTypeCache.cs
- SimpleLine.cs
- XmlBinaryReader.cs
- ValidationPropertyAttribute.cs
- UInt16Converter.cs
- Schema.cs
- KeyTimeConverter.cs
- EpmSourceTree.cs
- SharedUtils.cs
- SafeCryptoHandles.cs
- ITextView.cs
- NamespaceQuery.cs
- CategoryAttribute.cs
- Floater.cs
- SqlMetaData.cs
- ClientCultureInfo.cs
- QueryTask.cs
- XPathDocumentNavigator.cs
- MSAANativeProvider.cs
- EntityDataSourceChangingEventArgs.cs
- NameValueConfigurationCollection.cs
- SettingsBindableAttribute.cs
- TextElement.cs
- PrintingPermission.cs
- CustomAttributeBuilder.cs
- Contracts.cs
- SoapClientMessage.cs
- ScriptResourceHandler.cs
- WaitHandleCannotBeOpenedException.cs
- NullableLongMinMaxAggregationOperator.cs
- RouteItem.cs
- FontWeights.cs
- SmtpReplyReaderFactory.cs
- PageSetupDialog.cs
- FigureParaClient.cs
- SchemaTypeEmitter.cs
- ECDiffieHellmanPublicKey.cs
- ComponentEditorForm.cs
- InputLanguage.cs
- HttpDictionary.cs
- Parsers.cs
- ComplexType.cs
- x509store.cs
- WindowsListViewItemCheckBox.cs
- BamlReader.cs
- CustomValidator.cs
- LambdaCompiler.Unary.cs
- shaper.cs
- DbConnectionPool.cs
- XmlHierarchyData.cs
- FactoryGenerator.cs
- HiddenField.cs
- EntityDataSourceQueryBuilder.cs
- FieldMetadata.cs
- XmlReflectionMember.cs
- XmlILTrace.cs