Esempio n. 1
0
 public BotCallbackQueryAttribute(BotCallbackQueryType botCallbackQueryType)
 {
     BotCallbackQueryType = botCallbackQueryType;
 }
Esempio n. 2
0
        public static bool TryGetCallbackQuery(this IEnumerable <IBotCallbackQuery> callbackQueries, BotCallbackQueryType botCallbackQueryType, out IBotCallbackQuery botCallbackQuery)
        {
            if (callbackQueries is null)
            {
                throw new ArgumentNullException(nameof(callbackQueries));
            }

            if (botCallbackQueryType is BotCallbackQueryType.None)
            {
                botCallbackQuery = null;
                return(false);
            }

            foreach (var item in callbackQueries)
            {
                if (Attribute.IsDefined(item.GetType(), typeof(BotCallbackQueryAttribute)))
                {
                    var stateHandlerAttributes = (BotCallbackQueryAttribute[])Attribute.GetCustomAttributes(item.GetType(), typeof(BotCallbackQueryAttribute));
                    var attribute = stateHandlerAttributes.FirstOrDefault(x => x.BotCallbackQueryType == botCallbackQueryType);
                    if (attribute is not null)
                    {
                        botCallbackQuery = item;
                        return(true);
                    }
                }
            }

            botCallbackQuery = null;
            return(false);
        }