|
using System;
using System.Collections;
namespace EventsAcrossControls
{
internal class CachedEvent
{
private readonly IDictionary items;
private object key;
public CachedEvent (IDictionary items, object key)
{
this.items = items;
this.key = key;
}
private Delegate Listeners
{
set { items [key] = value; }
get { return (Delegate) items [key]; }
}
public void Add (MulticastDelegate newListener)
{
Listeners = Delegate.Combine(Listeners, newListener);
}
public void Remove (MulticastDelegate formerListener)
{
Listeners = Delegate.Remove(Listeners, formerListener);
}
public void Invoke (object sender, EventArgs arguments)
{
Delegate listeners = Listeners;
if (listeners != null) listeners.DynamicInvoke(new object[] {sender, arguments});
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have programmed applications in ASP.NET from the very beginning. My favourite .NET language is C#, and I am a fan of Test Driven Design. I was an experienced VB6 coder before the .NET era. I have also done some Transacted SQL programming in Sql Server. Although I have made a career on Microsoft technology, I have browsed enough Java code to read it fluently, and I find Smalltalk and Ruby very interesting.
I live a few kilometers away from Oslo.
My email is
thomas.eyde@gmail.com.