public override Channel Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { JsonDocument document = JsonDocument.ParseValue(ref reader); Channel channel = null; switch (document.RootElement.GetProperty("type").ToObject <ChannelTypes>(options)) { case ChannelTypes.DmChannel: case ChannelTypes.DmGroup: case ChannelTypes.StoreChannel: case ChannelTypes.NewsChannel: case ChannelTypes.TextChannel: channel = document.ToObject <TextChannel>(options); (channel as TextChannel).Messages = new MessageCollection(_cacheContext.GetCache <ulong, Message>(), _restContext, options, _logger, channel.Id); break; case ChannelTypes.VoiceChannel: channel = document.ToObject <VoiceChannel>(options); break; case ChannelTypes.GuildCategory: channel = document.ToObject <GuildCategory>(options); break; default: break; } return(channel); }
public override UserCollection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { UserCollection usersCollection = new UserCollection(_cacheContext.GetCache <ulong, User>(), _logger); JsonDocument document = JsonDocument.ParseValue(ref reader); Span <User> users = document.ToObject <User[]>(options); for (int i = 0; i < users.Length; i++) { usersCollection.Caching(ref users[i]); _datas.Users.Caching(ref users[i]); } return(usersCollection); }
public override ChannelCollection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { ChannelCollection channelCollection = new ChannelCollection(_cacheContext.GetCache <ulong, Channel>(), _restContext, options, _logger); JsonDocument document = JsonDocument.ParseValue(ref reader); Span <Channel> channels = document.ToObject <Channel[]>(options); for (int i = 0; i < channels.Length; i++) { if (channels[i] == null) { continue; } channelCollection.Caching(ref channels[i]); _datas.Channels.Caching(ref channels[i]); } return(channelCollection); }
public void InitCollections() { Guilds = new GuildCollection(_cacheContext.GetCache <ulong, Guild>(), Logger); Users = new UserCollection(_cacheContext.GetCache <ulong, User>(), Logger); Channels = new ChannelCollection(_cacheContext.GetCache <ulong, Channel>(), _restContext, _serializerOptions, Logger); }