I have a custom class that acts like an event to most of the code base, but adds some additional functionality to internal classes. The advantage this class gives me is that I can provide a single access point for subscribing to the event, but can also pass the event around internally so that the appropriate system to invoke the event can be changed dynamically. The biggest issue I've run into is that Visual Studio will no longer auto generate event handlers when pressing Tab after += which I've found very annoying.
I've already looked into writing a Visual Studio extension, but the ICompletionSource seemed to mainly just handle auto-completing one continuous string of characters and adding the event handler outside of the current method seemed like it would be pretty difficult not to mention figuring out when the text context was one of the custom events and properly naming the new event handler.
Below is the simplest version of the custom event class as an example in case it helps:
using System;
public class CustomEvent
{
public delegate void CustomEventDelegate();
private event CustomEventDelegate customEvent;
public static CustomEvent operator +(CustomEvent e, CustomEventDelegate del)
{
e.customEvent = (CustomEventDelegate)Delegate.Combine(e.customEvent, del);
return e;
}
public static CustomEvent operator -(CustomEvent e, CustomEventDelegate del)
{
e.customEvent = (CustomEventDelegate)Delegate.Remove(e.customEvent, del);
return e;
}
internal void Invoke()
{
customEvent?.Invoke();
}
}