Code:
/ 4.0 / 4.0 / untmp / 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;
///
/// Provides a simple list of delegates. This class cannot be inherited.
///
[HostProtection(SharedState = true)]
public sealed class EventHandlerList : IDisposable {
ListEntry head;
Component parent;
///
/// 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;
}
///
/// Gets or sets the delegate for the specified key.
///
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);
}
}
}
///
/// [To be supplied.]
///
[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);
}
}
/// 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;
}
}
///
/// [To be supplied.]
///
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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Mutex.cs
- FilterQuery.cs
- EntityContainerEntitySet.cs
- BroadcastEventHelper.cs
- ApplicationCommands.cs
- RC2CryptoServiceProvider.cs
- WorkflowApplicationTerminatedException.cs
- InvalidFilterCriteriaException.cs
- TemplateBamlTreeBuilder.cs
- ScriptDescriptor.cs
- Pkcs7Recipient.cs
- MatrixAnimationUsingKeyFrames.cs
- KeyBinding.cs
- HeaderElement.cs
- InteropAutomationProvider.cs
- ImageAutomationPeer.cs
- RequestQueue.cs
- OptimisticConcurrencyException.cs
- ApplyImportsAction.cs
- BufferedStream.cs
- FrameDimension.cs
- ActivityCodeDomSerializationManager.cs
- XmlIgnoreAttribute.cs
- EntityModelBuildProvider.cs
- CapabilitiesState.cs
- XmlSchemaAll.cs
- TemplateNameScope.cs
- WindowsAuthenticationModule.cs
- GridViewRow.cs
- URL.cs
- StringConcat.cs
- _ShellExpression.cs
- TreeNodeCollectionEditor.cs
- Vector3DConverter.cs
- EventDescriptorCollection.cs
- BehaviorEditorPart.cs
- SvcMapFileLoader.cs
- CodeDelegateInvokeExpression.cs
- JournalEntry.cs
- OutOfMemoryException.cs
- HttpListenerRequestUriBuilder.cs
- ValueProviderWrapper.cs
- OneOfElement.cs
- ErrorLog.cs
- RSAPKCS1SignatureFormatter.cs
- InputScopeAttribute.cs
- UdpChannelFactory.cs
- ContentDisposition.cs
- FileDetails.cs
- StaticResourceExtension.cs
- TimeSpan.cs
- WindowsTokenRoleProvider.cs
- ListItemConverter.cs
- RuntimeConfigLKG.cs
- AnonymousIdentificationSection.cs
- DisableDpiAwarenessAttribute.cs
- AddInAttribute.cs
- SQLInt32Storage.cs
- ImplicitInputBrush.cs
- StickyNote.cs
- ProfileProvider.cs
- ACL.cs
- RenderData.cs
- TemplateControlCodeDomTreeGenerator.cs
- MediaContextNotificationWindow.cs
- ModelFunctionTypeElement.cs
- DateTime.cs
- CodeDirectoryCompiler.cs
- TextSelection.cs
- MessageSecurityVersion.cs
- ExpandedWrapper.cs
- DataGridViewRowPostPaintEventArgs.cs
- StylusTip.cs
- DataMisalignedException.cs
- XPathNodeIterator.cs
- QuaternionConverter.cs
- XmlEncoding.cs
- XmlBaseWriter.cs
- AddInAttribute.cs
- InitializerFacet.cs
- Timer.cs
- SqlDataSourceConfigureSelectPanel.cs
- OletxTransactionManager.cs
- DbConnectionInternal.cs
- SystemException.cs
- PassportPrincipal.cs
- TagPrefixAttribute.cs
- WpfPayload.cs
- TemplateBindingExtension.cs
- FixedPageAutomationPeer.cs
- XmlHierarchyData.cs
- Preprocessor.cs
- HttpResponseHeader.cs
- XhtmlTextWriter.cs
- PackageRelationshipCollection.cs
- DurationConverter.cs
- ElementNotEnabledException.cs
- SubqueryRules.cs
- DriveInfo.cs
- LookupBindingPropertiesAttribute.cs