- Update of ControlBase for partial rendering options - Updating serveral base classes to better asyc event management - separating Enums into different folder - some small bug fixes - removed "CustomEventManagement" cause it doesnt make sense now
26 lines
863 B
C#
26 lines
863 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace TelegramBotBase.Base
|
|
{
|
|
public static class Async
|
|
{
|
|
public delegate Task AsyncEventHandler<TEventArgs>(object sender, TEventArgs e) where TEventArgs : EventArgs;
|
|
|
|
public static IEnumerable<AsyncEventHandler<TEventArgs>> GetHandlers<TEventArgs>(
|
|
this AsyncEventHandler<TEventArgs> handler)
|
|
where TEventArgs : EventArgs
|
|
=> handler.GetInvocationList().Cast<AsyncEventHandler<TEventArgs>>();
|
|
|
|
public static Task InvokeAllAsync<TEventArgs>(this AsyncEventHandler<TEventArgs> handler, object sender, TEventArgs e)
|
|
where TEventArgs : EventArgs
|
|
=> Task.WhenAll(
|
|
handler.GetHandlers()
|
|
.Select(handleAsync => handleAsync(sender, e)));
|
|
|
|
}
|
|
}
|