Proposal: allow events as method parameters #9598
Replies: 3 comments 17 replies
-
It doesn't make sense. How can you pass an event? That's like trying to pass a property. Under the hood, they are just mapped to methods C# never should have implemented |
Beta Was this translation helpful? Give feedback.
-
You could use |
Beta Was this translation helpful? Give feedback.
-
This is a duplicate of #2506. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, events aren't first-class citizens and can only ever be used on the LHS of an
+=
or-=
expression. However, that makes delegating the possibility to add or remove handlers to a different place in the program a bit cumbersome.Take Rx.NET
Observable.FromEventPattern<TDelegate, TEventArgs>
as an example. Currently, it looks like this:My idea is to allow methods to have an
event
parameter. Inside the method, the parameter is treated like anevent
member itself, meaning it may only be used on the LHS of+=
or-=
, or to be passed to anotherevent
parameter. This would allow for this code:It basically enables you to push lambda creation further down into a centralized location, rather than requiring it at the highest level, or maybe sometimes omit the lambda altogether
all while retaining the benefits of the current event restrictions to maintain control compared to raw delegates.
Beta Was this translation helpful? Give feedback.
All reactions