public override AbstractGuildChannel CreateEntry(JsonElement Data) { int Type = Data.GetProperty("type").GetInt32(); AbstractGuildChannel Channel = null; switch (Type) { case (int)ChannelType.Text: Channel = new GuildTextChannel(Client, Guild, Data); break; case (int)ChannelType.Voice: Channel = new GuildVoiceChannel(Client, Guild, Data); break; case (int)ChannelType.Category: Channel = new GuildCategoryChannel(Client, Guild, Data); break; case (int)ChannelType.News: Channel = new GuildNewsChannel(Client, Guild, Data); break; case (int)ChannelType.Store: Channel = new GuildStoreChannel(Client, Guild, Data); break; } _Cache.Add(Channel.Id, Channel); return(Channel); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject json = JObject.Load(reader); string jsonString = json.ToString(); ChannelType type = Channel.GetChannelType(json["type"].ToString()); IChannel result; switch (type) { case ChannelType.DirectMessage: result = new DMTextChannel(); break; case ChannelType.GroupDirectMessage: result = new GroupDMTextChannel(); break; case ChannelType.GuildCategory: result = new GuildCategory(); break; case ChannelType.GuildNews: result = new GuildNewsChannel(); break; case ChannelType.GuildStore: result = new GuildStoreChannel(); break; case ChannelType.GuildText: result = new GuildTextChannel(); break; case ChannelType.GuildVoice: result = new GuildVoiceChannel(); break; default: throw new Exception("Unknown channel type"); //TODO : адекватное исключение } JsonConvert.PopulateObject(jsonString, result); return(result); }