Skip to content

Commit

Permalink
Update MessageRunConverter.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Agash committed Jun 2, 2024
1 parent ff8f741 commit 6e99b69
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions Helpers/MessageRunConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ internal class MessageRunConverter : JsonConverter<MessageRun>
{
using JsonDocument doc = JsonDocument.ParseValue(ref reader);

if (doc.RootElement.TryGetProperty("emoji", out _))
{
return JsonSerializer.Deserialize<MessageEmoji>(doc.RootElement, options);
}
else
{
return doc.RootElement.TryGetProperty("text", out _)
return doc.RootElement.TryGetProperty("emoji", out _)
? JsonSerializer.Deserialize<MessageEmoji>(doc.RootElement, options)
: doc.RootElement.TryGetProperty("text", out _)
? (MessageRun?)JsonSerializer.Deserialize<MessageText>(doc.RootElement, options)
: throw new JsonException("Invalid MessageRun format.");
}
}

public override void Write(Utf8JsonWriter writer, MessageRun value, JsonSerializerOptions options) => throw new NotImplementedException(); // Implement if needed
Expand Down

0 comments on commit 6e99b69

Please sign in to comment.