mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
26 lines
702 B
C#
26 lines
702 B
C#
using System.Reflection;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Telegram.Bot.Types;
|
|
|
|
namespace West.TelegramBot.ChatQuotes.Json;
|
|
|
|
public class NullToEmptyObjectValueProvider : IValueProvider
|
|
{
|
|
private readonly PropertyInfo _memberInfo;
|
|
public NullToEmptyObjectValueProvider(PropertyInfo memberInfo)
|
|
{
|
|
_memberInfo = memberInfo;
|
|
}
|
|
|
|
public object? GetValue(object target)
|
|
{
|
|
var result = _memberInfo.GetValue(target);
|
|
if (_memberInfo.PropertyType == typeof(Message) && result == null) result = new object();
|
|
return result;
|
|
}
|
|
|
|
public void SetValue(object target, object? value)
|
|
{
|
|
_memberInfo.SetValue(target, value);
|
|
}
|
|
} |