| | | 1 | | using System.ComponentModel; |
| | | 2 | | |
| | | 3 | | namespace TeleFlow.Telegram; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Infrastructure error handler metadata emitted by TeleFlow source generators. |
| | | 7 | | /// This API is not intended to be used by application code. |
| | | 8 | | /// </summary> |
| | | 9 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | | 10 | | public sealed class TelegramGeneratedErrorHandlerDescriptor |
| | | 11 | | { |
| | | 12 | | public TelegramGeneratedErrorHandlerDescriptor( |
| | | 13 | | Type handlerType, |
| | | 14 | | string methodName, |
| | | 15 | | Type? exceptionType, |
| | | 16 | | Type? telegramContextType, |
| | | 17 | | int registrationOrder, |
| | | 18 | | string? moduleName, |
| | | 19 | | IReadOnlyList<TelegramGeneratedErrorHandlerParameterDescriptor> parameters, |
| | | 20 | | TelegramGeneratedErrorHandlerInvoker invoker) |
| | | 21 | | { |
| | 130 | 22 | | ArgumentNullException.ThrowIfNull(handlerType); |
| | 130 | 23 | | ArgumentException.ThrowIfNullOrWhiteSpace(methodName); |
| | 130 | 24 | | ArgumentNullException.ThrowIfNull(parameters); |
| | 130 | 25 | | ArgumentNullException.ThrowIfNull(invoker); |
| | | 26 | | |
| | 130 | 27 | | if (exceptionType is not null && !typeof(Exception).IsAssignableFrom(exceptionType)) |
| | | 28 | | { |
| | 0 | 29 | | throw new InvalidOperationException( |
| | 0 | 30 | | $"Generated Telegram error handler exception type '{exceptionType.FullName}' must derive from Exception. |
| | | 31 | | } |
| | | 32 | | |
| | 130 | 33 | | if (telegramContextType is not null && !typeof(TelegramUpdateContext).IsAssignableFrom(telegramContextType)) |
| | | 34 | | { |
| | 0 | 35 | | throw new InvalidOperationException( |
| | 0 | 36 | | $"Generated Telegram error handler context type '{telegramContextType.FullName}' must derive from Telegr |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | HandlerType = handlerType; |
| | | 40 | | MethodName = methodName; |
| | | 41 | | ExceptionType = exceptionType; |
| | | 42 | | TelegramContextType = telegramContextType; |
| | | 43 | | RegistrationOrder = registrationOrder; |
| | | 44 | | ModuleName = moduleName; |
| | 130 | 45 | | Parameters = CopyValues(parameters); |
| | | 46 | | Invoker = invoker; |
| | 130 | 47 | | } |
| | | 48 | | |
| | | 49 | | public Type HandlerType { get; } |
| | | 50 | | |
| | | 51 | | public string MethodName { get; } |
| | | 52 | | |
| | | 53 | | public Type? ExceptionType { get; } |
| | | 54 | | |
| | | 55 | | public Type? TelegramContextType { get; } |
| | | 56 | | |
| | | 57 | | public int RegistrationOrder { get; } |
| | | 58 | | |
| | | 59 | | public string? ModuleName { get; } |
| | | 60 | | |
| | | 61 | | public IReadOnlyList<TelegramGeneratedErrorHandlerParameterDescriptor> Parameters { get; } |
| | | 62 | | |
| | | 63 | | public TelegramGeneratedErrorHandlerInvoker Invoker { get; } |
| | | 64 | | |
| | | 65 | | private static TValue[] CopyValues<TValue>(IReadOnlyList<TValue>? values) |
| | | 66 | | { |
| | 130 | 67 | | return values is null || values.Count == 0 |
| | 130 | 68 | | ? [] |
| | 130 | 69 | | : values.ToArray(); |
| | | 70 | | } |
| | | 71 | | } |