< Summary

Information
Class: TeleFlow.Annotations.ChatIdAttribute
Assembly: TeleFlow.Annotations
File(s): /_/src/TeleFlow.Annotations/Filters/ChatIdAttribute.cs
Line coverage
75%
Covered lines: 6
Uncovered lines: 2
Coverable lines: 8
Total lines: 33
Line coverage: 75%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%4475%

File(s)

/_/src/TeleFlow.Annotations/Filters/ChatIdAttribute.cs

#LineLine coverage
 1namespace TeleFlow.Annotations;
 2/// <summary>
 3/// Restricts a handler or handler class to specific Telegram chat ids.
 4/// </summary>
 5[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
 6public sealed class ChatIdAttribute : TeleFlowAttribute
 7{
 8    /// <summary>
 9    /// Creates a chat id filter.
 10    /// </summary>
 11    /// <param name="chatIds">Telegram chat ids allowed to match.</param>
 1912    public ChatIdAttribute(params long[] chatIds)
 13    {
 1914        ArgumentNullException.ThrowIfNull(chatIds);
 15
 1916        if (chatIds.Length == 0)
 17        {
 018            throw new ArgumentException("At least one Telegram chat id must be specified.", nameof(chatIds));
 19        }
 20
 3821        if (chatIds.Any(static chatId => chatId == 0))
 22        {
 023            throw new ArgumentException("Telegram chat ids must not be zero.", nameof(chatIds));
 24        }
 25
 1926        ChatIds = chatIds.ToArray();
 1927    }
 28
 29    /// <summary>
 30    /// Telegram chat ids allowed to match.
 31    /// </summary>
 32    public IReadOnlyList<long> ChatIds { get; }
 33}

Methods/Properties

.ctor(System.Int64[])