* Added "LazyInitialize" property to "HandlerDescriptor" to make post-creation operation (required for BranchingHandler)

* Tweaked "HandlersProvider" implementation to fit new HandlerDescriptor property
* Fixed "BranchingHandler"'s descriptor creation logic
This commit is contained in:
2025-07-28 03:53:13 +04:00
parent 5a93623469
commit 6a18d9765b
5 changed files with 51 additions and 37 deletions
@@ -43,14 +43,6 @@ namespace Telegrator.Handlers.Components
protected BranchingUpdateHandler(UpdateType handlingUpdateType)
: base(handlingUpdateType) { }
/// <summary>
/// Initializes a new instance of the <see cref="BranchingUpdateHandler{TUpdate}"/> class with a specific branch method.
/// </summary>
/// <param name="handlingUpdateType">The type of update this handler processes.</param>
/// <param name="branch">The specific branch method to execute.</param>
protected BranchingUpdateHandler(UpdateType handlingUpdateType, MethodInfo branch)
: base(handlingUpdateType) => branchMethodInfo = branch;
/// <summary>
/// Describes all handler branches in this class.
/// </summary>
@@ -92,7 +84,7 @@ namespace Telegrator.Handlers.Components
{
handlerAttribute = HandlerInspector.GetHandlerAttribute(branch);
}
finally
catch
{
_ = 0xBAD + 0xC0DE;
}
@@ -105,7 +97,7 @@ namespace Telegrator.Handlers.Components
HandlerInspector.GetStateKeeperAttribute(branch),
branchFiltersList.ToArray());
return new HandlerBranchDescriptor(branch, HandlingUpdateType, handlerAttribute.GetIndexer(), filtersSet);
return new HandlerBranchDescriptor(thisType, branch, HandlingUpdateType, handlerAttribute.GetIndexer(), filtersSet);
}
/// <summary>
@@ -160,15 +152,15 @@ namespace Telegrator.Handlers.Components
private class HandlerBranchDescriptor : HandlerDescriptor
{
public HandlerBranchDescriptor(MethodInfo method, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters)
: base(DescriptorType.General, method.DeclaringType, updateType, indexer, filters)
public HandlerBranchDescriptor(Type decalringType, MethodInfo method, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters) : base(DescriptorType.General, decalringType, updateType, indexer, filters)
{
DisplayString = string.Format("{0}+{1}", method.DeclaringType.Name, method.Name);
InstanceFactory = () =>
DisplayString = HandlerInspector.GetDisplayName(method) ?? string.Format("{0}+{1}", method.DeclaringType.Name, method.Name);
LazyInitialization = handler =>
{
BranchingUpdateHandler<TUpdate> handler = (BranchingUpdateHandler<TUpdate>)Activator.CreateInstance(method.DeclaringType);
handler.branchMethodInfo = method;
return handler;
if (handler is not BranchingUpdateHandler<TUpdate> brancher)
throw new InvalidDataException();
brancher.branchMethodInfo = method;
};
}
}