-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed serialization for TweetMediaType.AnimatedGif. Added Url to Twee…
…tMedia because TweetMediaType.Photo has Url and not PreviewImageUrl.
- Loading branch information
Showing
5 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/LinqToTwitter6/LinqToTwitter/Tweet/TweetMediaTypeConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace LinqToTwitter | ||
{ | ||
public class TweetMediaTypeConverter : JsonConverter<TweetMediaType> | ||
{ | ||
public override TweetMediaType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return reader.GetString() switch | ||
{ | ||
"animated_gif" => TweetMediaType.AnimatedGif, | ||
"photo" => TweetMediaType.Photo, | ||
"video" => TweetMediaType.Video, | ||
_ => TweetMediaType.None | ||
}; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, TweetMediaType value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue( | ||
value switch | ||
{ | ||
TweetMediaType.AnimatedGif => "animated_gif", | ||
TweetMediaType.Photo => "photo", | ||
TweetMediaType.Video => "video", | ||
_ => "" | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters