public override object?ReadJson(JsonReader reader, Type objectType, object?existingValue,
                                        [NotNull] JsonSerializer serializer)
        {
            var         jo    = JObject.Load(reader);
            var         type  = Enum.Parse <PromptDataType>((string)jo["type"] !);
            var         data  = jo["s"] !.CreateReader();
            IPromptData state = type switch
            {
                PromptDataType.MessageSingleUser => serializer.Deserialize <PromptDataMessage>(data) !,
                PromptDataType.ReactionSingleUser => serializer.Deserialize <PromptDataReaction>(data) !,
                PromptDataType.RichDisplay => serializer.Deserialize <RichDisplay>(data) !,
                _ => throw new ArgumentOutOfRangeException(nameof(type))
            };

            return(new PromptData(null !, type, state));
        }
Example #2
0
 public PromptData(IClient client, PromptDataType type, IPromptData state)
 {
     Client = client;
     Type   = type;
     Data   = state;
 }