| | | 1 | | using System.Diagnostics.CodeAnalysis; |
| | | 2 | | |
| | | 3 | | namespace TeleFlow.Annotations; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Marks a method as a Telegram handler error handler. |
| | | 7 | | /// </summary> |
| | | 8 | | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] |
| | | 9 | | [SuppressMessage( |
| | | 10 | | "Performance", |
| | | 11 | | "CA1813:Avoid unsealed attributes", |
| | | 12 | | Justification = "The non-generic catch-all error attribute is intentionally inherited by ErrorAttribute<TException>. |
| | | 13 | | public class ErrorAttribute : TeleFlowAttribute |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Creates a catch-all handler error attribute. |
| | | 17 | | /// </summary> |
| | 40 | 18 | | public ErrorAttribute() |
| | | 19 | | { |
| | 40 | 20 | | } |
| | | 21 | | |
| | 113 | 22 | | internal ErrorAttribute(Type exceptionType) |
| | | 23 | | { |
| | 113 | 24 | | ArgumentNullException.ThrowIfNull(exceptionType); |
| | | 25 | | |
| | | 26 | | ExceptionType = exceptionType; |
| | 113 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Exception type handled by the method, or <see langword="null"/> for catch-all error handlers. |
| | | 31 | | /// </summary> |
| | | 32 | | public Type? ExceptionType { get; } |
| | | 33 | | } |
| | | 34 | | /// <summary> |
| | | 35 | | /// Marks a method as handling a specific exception type raised by a Telegram handler. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <typeparam name="TException">Exception type handled by the method.</typeparam> |
| | | 38 | | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] |
| | | 39 | | public sealed class ErrorAttribute<TException> : ErrorAttribute |
| | | 40 | | where TException : Exception |
| | | 41 | | { |
| | | 42 | | /// <summary> |
| | | 43 | | /// Creates a typed handler error attribute. |
| | | 44 | | /// </summary> |
| | | 45 | | public ErrorAttribute() |
| | | 46 | | : base(typeof(TException)) |
| | | 47 | | { |
| | | 48 | | } |
| | | 49 | | } |