Skip to content

Instantly share code, notes, and snippets.

Created November 2, 2012 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4004086 to your computer and use it in GitHub Desktop.
Save anonymous/4004086 to your computer and use it in GitHub Desktop.
Recreation of RX call to CreateDelegate that throws an exception.
using System;
namespace CreateDelegateTest
{
class Program
{
static void Main(string[] args)
{
// Create the shim.
var shim = new Shim();
// Create the delegate.
var ev = (EventHandler<EventArgs>)Delegate.CreateDelegate(typeof(EventHandler<EventArgs>),
new Action<EventArgs>(shim.Next),
typeof(Action<EventArgs>).GetMethod("Invoke"));
ev(null, EventArgs.Empty);
}
}
public class Shim
{
public void Next(EventArgs e)
{
Console.WriteLine("Fired");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment