Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created June 14, 2011 19:51
Show Gist options
  • Save ElemarJR/1025716 to your computer and use it in GitHub Desktop.
Save ElemarJR/1025716 to your computer and use it in GitHub Desktop.
public class DummyObject
{
public void Touch()
{
if (_Touched != null)
this._Touched(this, EventArgs.Empty);
}
EventHandler _Touched;
public event EventHandler Touched
{
add {
var mi = value.Method;
WeakEventHandler.Register(
this,
value.Target,
(s, h) => s._Touched += h,
(s, h) => s._Touched -= h,
(source, sender, args) => mi.Invoke(source, new [] { sender, args} )
);
}
remove { _Touched -= value; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment