diff --git a/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj b/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj index cd0ecc2..0ca4cb4 100644 --- a/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj +++ b/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj @@ -15,7 +15,7 @@ True LICENSE README.md - 1.15.3 + 1.15.4 diff --git a/Telegrator.Hosting/Telegrator.Hosting.csproj b/Telegrator.Hosting/Telegrator.Hosting.csproj index 822f40b..628ddbe 100644 --- a/Telegrator.Hosting/Telegrator.Hosting.csproj +++ b/Telegrator.Hosting/Telegrator.Hosting.csproj @@ -16,7 +16,7 @@ True LICENSE README.md - 1.15.3 + 1.15.4 diff --git a/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs b/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs index 4a20260..ac2aabe 100644 --- a/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs +++ b/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs @@ -10,16 +10,6 @@ namespace Telegrator.MadiatorCore.Descriptors /// public sealed class DescriptorAspectsSet { - /// - /// Gets a value indicating whether the handler implements . - /// - public bool SelfPre { get; private set; } - - /// - /// Gets a value indicating whether the handler implements . - /// - public bool SelfPost { get; private set; } - /// /// Gets the type of the external pre-processor, if specified via . /// @@ -33,14 +23,10 @@ namespace Telegrator.MadiatorCore.Descriptors /// /// Initializes a new instance of the class. /// - /// Whether the handler implements . /// The type of external pre-processor, if any. - /// Whether the handler implements . /// The type of external post-processor, if any. - public DescriptorAspectsSet(bool selfPre, Type? typedPre, bool selfPost, Type? typedPost) + public DescriptorAspectsSet(Type? typedPre, Type? typedPost) { - SelfPre = selfPre; - SelfPost = selfPost; TypedPre = typedPre; TypedPost = typedPost; } @@ -55,16 +41,13 @@ namespace Telegrator.MadiatorCore.Descriptors /// Thrown when handler claims to implement but doesn't. public async Task ExecutePre(UpdateHandlerBase handler, IHandlerContainer container, CancellationToken cancellationToken) { - if (SelfPre) + if (handler is IPreProcessor preProcessor) { - if (handler is not IPreProcessor preProcessor) - throw new InvalidOperationException(); - return await preProcessor.BeforeExecution(container, cancellationToken).ConfigureAwait(false); } else if (TypedPre != null) { - IPreProcessor preProcessor = (IPreProcessor)Activator.CreateInstance(TypedPre); + preProcessor = (IPreProcessor)Activator.CreateInstance(TypedPre); return await preProcessor.BeforeExecution(container, cancellationToken).ConfigureAwait(false); } @@ -81,16 +64,13 @@ namespace Telegrator.MadiatorCore.Descriptors /// Thrown when handler claims to implement but doesn't. public async Task ExecutePost(UpdateHandlerBase handler, IHandlerContainer container, CancellationToken cancellationToken) { - if (SelfPost) + if (handler is IPostProcessor postProcessor) { - if (handler is not IPostProcessor postProcessor) - throw new InvalidOperationException(); - return await postProcessor.AfterExecution(container, cancellationToken).ConfigureAwait(false); } else if (TypedPost != null) { - IPostProcessor postProcessor = (IPostProcessor)Activator.CreateInstance(TypedPost); + postProcessor = (IPostProcessor)Activator.CreateInstance(TypedPost); return await postProcessor.AfterExecution(container, cancellationToken).ConfigureAwait(false); } diff --git a/Telegrator/MadiatorCore/Descriptors/HandlerInspector.cs b/Telegrator/MadiatorCore/Descriptors/HandlerInspector.cs index 8e892db..99f9966 100644 --- a/Telegrator/MadiatorCore/Descriptors/HandlerInspector.cs +++ b/Telegrator/MadiatorCore/Descriptors/HandlerInspector.cs @@ -90,26 +90,9 @@ namespace Telegrator.MadiatorCore.Descriptors /// A containing the aspects configuration. public static DescriptorAspectsSet GetAspects(Type handlerType) { - bool selfPre = handlerType.GetInterface(nameof(IPreProcessor)) != null; - bool selfPost = handlerType.GetInterface(nameof(IPostProcessor)) != null; - Type? typedPre = null; - Type? typedPost = null; - - if (!selfPre) - { - Attribute? preAttr = handlerType.GetCustomAttribute(typeof(BeforeExecutionAttribute<>)); - if (preAttr != null) - typedPre = preAttr.GetType().GetGenericArguments()[0]; - } - - if (!selfPost) - { - Attribute? postAttr = handlerType.GetCustomAttribute(typeof(AfterExecutionAttribute<>)); - if (postAttr != null) - typedPost = postAttr.GetType().GetGenericArguments()[0]; - } - - return new DescriptorAspectsSet(selfPre, typedPre, selfPost, typedPost); + Type? typedPre = handlerType.GetCustomAttribute(typeof(BeforeExecutionAttribute<>))?.GetType().GetGenericArguments()[0]; + Type? typedPost = handlerType.GetCustomAttribute(typeof(AfterExecutionAttribute<>)).GetType().GetGenericArguments()[0]; + return new DescriptorAspectsSet(typedPre, typedPost); } } } diff --git a/Telegrator/Telegrator.csproj b/Telegrator/Telegrator.csproj index f08ca91..f5b6b74 100644 --- a/Telegrator/Telegrator.csproj +++ b/Telegrator/Telegrator.csproj @@ -17,7 +17,7 @@ telegram;bot;mediator;attributes;aspect;hosting;host;framework;easy;simple;handlers README.md LICENSE - 1.15.3 + 1.15.4