Optimizations to HandlersCollections

This commit is contained in:
2025-08-19 04:51:53 +04:00
parent 24c10ceb24
commit 890ee3616c
+6 -4
View File
@@ -16,7 +16,10 @@ namespace Telegrator.Providers
/// <param name="options">Optional configuration options for handler collecting.</param> /// <param name="options">Optional configuration options for handler collecting.</param>
public class HandlersCollection(ITelegratorOptions? options) : IHandlersCollection public class HandlersCollection(ITelegratorOptions? options) : IHandlersCollection
{ {
private readonly List<UpdateType> _allowedTypes = []; /// <summary>
/// Gets the collection of <see cref="UpdateType"/>'s allowed by registered handlers
/// </summary>
protected readonly List<UpdateType> _allowedTypes = [];
/// <summary> /// <summary>
/// Dictionary that organizes handler descriptors by update type. /// Dictionary that organizes handler descriptors by update type.
@@ -71,9 +74,8 @@ namespace Telegrator.Providers
throw new Exception("This handler (" + descriptor.HandlerType.FullName + "), must contain constructor without parameters."); throw new Exception("This handler (" + descriptor.HandlerType.FullName + "), must contain constructor without parameters.");
_allowedTypes.UnionAdd(descriptor.UpdateType); _allowedTypes.UnionAdd(descriptor.UpdateType);
MightAwaitAttribute[] mightAwaits = descriptor.HandlerType.GetCustomAttributes<MightAwaitAttribute>().ToArray(); foreach (MightAwaitAttribute mightAwaits in descriptor.HandlerType.GetCustomAttributes<MightAwaitAttribute>())
if (mightAwaits.Length > 0) _allowedTypes.UnionAdd(mightAwaits.UpdateTypes);
_allowedTypes.UnionAdd(mightAwaits.SelectMany(attr => attr.UpdateTypes));
IntersectCommands(descriptor); IntersectCommands(descriptor);
HandlerDescriptorList list = GetDescriptorList(descriptor); HandlerDescriptorList list = GetDescriptorList(descriptor);