I tried to do this:
public static EventHandler ToEventHandler(this Action callback)
{...}
for some syntactic sugar when I want to pass a simple method like void x()
to a method that's typed for an EventHandler
.
But when I try to call this like so:
SomeMethod(x.ToEventHandler());
I get a compiler error:
x() is a 'method', which is not valid in the given context
Since methods are first class citizens in .NET, I can't see why this shouldn't be possible. Why doesn't it like this, and is there another way to accomplish what I'm trying to do?