Metalama icon indicating copy to clipboard operation
Metalama copied to clipboard

Feature: reference IMethod as a delegate in a template

Open gfraiteur opened this issue 2 years ago • 5 comments

There is currently no way to reference an introduced method or an IMethod as a delegate i.e.

dictionary.OnDictionaryChanged += myDictionaryChangedMethod; //Doesn't like this since IMethod isn't a System.EventHandler

gfraiteur avatar Jul 21 '23 09:07 gfraiteur

Hello @gfraiteur, thank you for submitting this issue. We will try to get back to you as soon as possible. Note to the PostSharp team, this ticket is being tracked in our dashboard under ID TP-33565.

PostSharpBot avatar Jul 21 '23 09:07 PostSharpBot

Ideally support for this feature will also be paired with a way to unsubscribe from the event (e.g. within a Dispose or DisposeAsync method) as well - thanks!

WhitWaldo avatar Jul 21 '23 10:07 WhitWaldo

An interesting question is: to which delegate type? It could default to a Func or Action but I guess that in some cases you may want to pass your own delegate type.

gfraiteur avatar Jul 29 '23 06:07 gfraiteur

I think it'd need to be open to whatever it is that I pass it - my immediate need was to simply provide an Action for a third-party event, meaning I'd have little control over its shape. It could just as easily have required a Func instead.

WhitWaldo avatar Jul 31 '23 17:07 WhitWaldo

Raising the priority of this ticket because it seems both forgotten, simple, and good value.

gfraiteur avatar Jun 07 '24 06:06 gfraiteur