Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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;
///
/// 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.
//------------------------------------------------------------------------------
//
// 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
- Int64.cs
- DataGridTable.cs
- PrimitiveXmlSerializers.cs
- ObjectConverter.cs
- QilIterator.cs
- LocatorBase.cs
- ConfigXmlSignificantWhitespace.cs
- GridItem.cs
- ObjectQueryExecutionPlan.cs
- DataChangedEventManager.cs
- SequentialUshortCollection.cs
- Int32CollectionConverter.cs
- TCPClient.cs
- FontStyleConverter.cs
- PrefixHandle.cs
- ClientUrlResolverWrapper.cs
- DbSourceParameterCollection.cs
- InputBinding.cs
- LogicalCallContext.cs
- DispatcherTimer.cs
- XmlBaseReader.cs
- IndexingContentUnit.cs
- XmlSchemaFacet.cs
- StringValidator.cs
- WebException.cs
- WorkflowFormatterBehavior.cs
- HTMLTextWriter.cs
- MaskInputRejectedEventArgs.cs
- GraphicsPath.cs
- SetIterators.cs
- MissingMethodException.cs
- ButtonBase.cs
- LiteralText.cs
- TcpTransportElement.cs
- RequestCacheEntry.cs
- _DomainName.cs
- SharedRuntimeState.cs
- ValueTypeFieldReference.cs
- ProjectionPathBuilder.cs
- SecurityDescriptor.cs
- BaseResourcesBuildProvider.cs
- RowToFieldTransformer.cs
- NullRuntimeConfig.cs
- ObjectQueryExecutionPlan.cs
- Thumb.cs
- IEnumerable.cs
- CompilationSection.cs
- DeflateStream.cs
- XmlDataSourceNodeDescriptor.cs
- SessionEndingCancelEventArgs.cs
- Bold.cs
- WindowsStartMenu.cs
- ScriptManagerProxy.cs
- ColorConverter.cs
- MenuItemCollectionEditorDialog.cs
- ResumeStoryboard.cs
- HwndSourceKeyboardInputSite.cs
- AnnotationMap.cs
- CssClassPropertyAttribute.cs
- NameScopePropertyAttribute.cs
- NumberAction.cs
- Group.cs
- Process.cs
- MethodToken.cs
- XmlSchemas.cs
- SqlStream.cs
- ListMarkerLine.cs
- UnSafeCharBuffer.cs
- ObfuscateAssemblyAttribute.cs
- filewebrequest.cs
- WebReference.cs
- AsyncOperationContext.cs
- DragEvent.cs
- Rotation3D.cs
- BypassElement.cs
- ListViewCommandEventArgs.cs
- RuleElement.cs
- ToolStripGrip.cs
- SubMenuStyleCollection.cs
- AnnotationHighlightLayer.cs
- ManipulationLogic.cs
- BooleanFacetDescriptionElement.cs
- CryptoKeySecurity.cs
- StreamMarshaler.cs
- ClientCultureInfo.cs
- XpsTokenContext.cs
- InternalConfigEventArgs.cs
- DEREncoding.cs
- CDSCollectionETWBCLProvider.cs
- DefaultAssemblyResolver.cs
- ComboBox.cs
- CollectionBase.cs
- _HelperAsyncResults.cs
- SByteConverter.cs
- BaseTransportHeaders.cs
- CellQuery.cs
- DiscreteKeyFrames.cs
- PolyLineSegment.cs
- SrgsElement.cs
- ScriptReferenceEventArgs.cs