You can use MethodInfo.GetCurrentMethodlambda inside your lambda to extract MethodInfo.
With MethodInfo, you can use Delegate.CreateDelegateto get a correctly typed delegate representing your lambda.
, , .
class MyClass
{
public event EventHandler TheEvent;
void TestIt()
{
TheEvent += (sender, eventargs) =>
{
Console.WriteLine("Handled!");
var fn = (EventHandler)Delegate.CreateDelegate(
typeof(EventHandler), sender,
(MethodInfo)MethodInfo.GetCurrentMethod());
TheEvent -= fn;
};
TheEvent(this, EventArgs.Empty);
TheEvent(this, EventArgs.Empty);
}
}