Partial events #8064
Unanswered
thomaslevesque
asked this question in
Language Ideas
Partial events
#8064
Replies: 3 comments 8 replies
-
One thing that I think would need consideration is how the declaring class would be expected to raise the event. |
Beta Was this translation helpful? Give feedback.
3 replies
-
Could you please include a full sample of the implementation part you would like to generate for the partial event, and how the event would be used in user code? Thanks! |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
At the moment, events cannot be declared
partial
in C#. I realize needing to do this isn't very common, but now that we have rich code generation features, it could be useful to allow it.My specific use case is to make a generator for weak events (i.e. events that only keep weak references to the handlers). I have a library that provides a generic weak event implementation. At the moment the library has certain restrictions (not relevant to this discussion, but you can look at the issue if you're interested), which could probably be solved by using a source generator. Ideally I'd like the user to declare an event like this:
And the library would generate the event implementation, and a method to raise the event. In my use case it would probably similar to this:
But since events can't be partial, it's not currently possible to use this approach.
This idea is actually pretty similar to the Partial properties proposal, which wants to allow partial properties to allow code generation scenarios.
Like for properties, it would be required to have an implementing declaration of the event (whether it's provided manually or by a generator).
Beta Was this translation helpful? Give feedback.
All reactions