mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
also need export Telegram types
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
using Kruzya.TelegramBot.Core.Attributes;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
@@ -47,7 +49,20 @@ namespace Kruzya.TelegramBot.Core.Service
|
||||
.Where(definedType => definedType.GetAttribute<AllowedSerializableTypeAttribute>() != null)
|
||||
.ToDictionary(type => type.GetAttribute<AllowedSerializableTypeAttribute>().Name);
|
||||
|
||||
foreach (var pair in allowedSerializationTypes)
|
||||
// Also need allow any Telegram Bot API type.
|
||||
var telegramTypes = typeof(Telegram.Bot.Types.Update).Assembly.ExportedTypes
|
||||
.Where(definedType => definedType.GetAttribute<JsonObjectAttribute>() != null)
|
||||
.ToDictionary(type => type.FullName);
|
||||
|
||||
var mergedDictionaryTypes = new List<IDictionary<string, Type>>
|
||||
{
|
||||
telegramTypes,
|
||||
allowedSerializationTypes
|
||||
}
|
||||
.SelectMany(dict => dict)
|
||||
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
|
||||
foreach (var pair in mergedDictionaryTypes)
|
||||
{
|
||||
binder.RegisterAllowedType(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user