/// <summary> /// Create a delegate from an asynchronous (non-cancellable) action. /// </summary> /// <typeparam name="TAttributed">Type of object that contains methods marked with [EventHandler].</typeparam> /// <typeparam name="TEvent">Type of event that is handled by the EventHandlerDelegate.</typeparam> /// <param name="attributedObjectFactory">Factory delegate which produces an instance of <typeparamref name="TAttributed"/>.</param> /// <returns>Instance of EventHandlerDelegate.</returns> private EventHandlerDelegate createNonCancellableAsyncDelegate <TAttributed, TEvent>(Func <TAttributed> attributedObjectFactory) where TAttributed : class where TEvent : class, IEvent { Func <TAttributed, TEvent, Task> asyncAction = (Func <TAttributed, TEvent, Task>)MethodInfo.CreateDelegate(typeof(Func <TAttributed, TEvent, Task>)); return(EventHandlerDelegateBuilder.FromDelegate(attributedObjectFactory, asyncAction)); }
/// <summary> /// Create a delegate from a synchronous action. /// </summary> /// <typeparam name="TAttributed">Type of object that contains methods marked with [EventHandler].</typeparam> /// <typeparam name="TEvent">Type of event that is handled by the EventHandlerDelegate.</typeparam> /// <param name="attributedObjectFactory">Factory delegate which produces an instance of <typeparamref name="TAttributed"/>.</param> /// <returns>Instance of EventHandlerDelegate.</returns> private EventHandlerDelegate createWrappedSyncDelegate <TAttributed, TEvent>(Func <TAttributed> attributedObjectFactory) where TAttributed : class where TEvent : class, IEvent { Action <TAttributed, TEvent> action = (Action <TAttributed, TEvent>)MethodInfo.CreateDelegate(typeof(Action <TAttributed, TEvent>)); return(EventHandlerDelegateBuilder.FromDelegate(attributedObjectFactory, action)); }