also need export Telegram types

This commit is contained in:
2024-06-06 02:03:12 +03:00
parent 179e6cc3ef
commit b43e3ab39a
+16 -1
View File
@@ -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);
}