mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
WiP storage for modules
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Data
|
||||
{
|
||||
public class BotUserValue
|
||||
{
|
||||
[Key]
|
||||
public Guid BotUserValueId { get; set; }
|
||||
|
||||
public BotUser BotUser { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public byte[] Value
|
||||
{
|
||||
get
|
||||
{
|
||||
var fmt = new BinaryFormatter();
|
||||
using var memStream = new MemoryStream();
|
||||
fmt.Serialize(memStream, data);
|
||||
|
||||
return memStream.ToArray();
|
||||
}
|
||||
set
|
||||
{
|
||||
var fmt = new BinaryFormatter();
|
||||
using var memStream = new MemoryStream();
|
||||
memStream.Write(value);
|
||||
memStream.Position = 0;
|
||||
|
||||
data = fmt.Deserialize(memStream);
|
||||
}
|
||||
}
|
||||
|
||||
[NonSerialized] public object data;
|
||||
|
||||
public T GetValue<T>() => (T) data;
|
||||
public void SetValue<T>(T value) => data = value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user