Обнновлено до .net10

This commit is contained in:
FrigaT
2026-04-10 15:05:32 +03:00
parent 11d0b0d72f
commit 8444fc5f8e
386 changed files with 6361 additions and 7164 deletions

View File

@@ -0,0 +1,37 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace YandexMusic.API.Models.Landing.Entity.Entities.Context;
/// <summary>Конвертер для контекста воспроизведения (альбом, исполнитель, плейлист).</summary>
public class YPlayContextConverter : JsonConverter<YPlayContext>
{
public override YPlayContext? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
throw new JsonException("Ожидается объект контекста");
using var doc = JsonDocument.ParseValue(ref reader);
var root = doc.RootElement;
var contextProp = root.GetProperty("context");
var contextStr = contextProp.GetString();
if (!Enum.TryParse<YPlayContextType>(contextStr, true, out var contextType))
throw new JsonException($"Неизвестный тип контекста: {contextStr}");
var rawText = root.GetRawText();
return contextType switch
{
YPlayContextType.Album => JsonSerializer.Deserialize<YPlayContextAlbum>(rawText, options),
YPlayContextType.Artist => JsonSerializer.Deserialize<YPlayContextArtist>(rawText, options),
YPlayContextType.Playlist => JsonSerializer.Deserialize<YPlayContextPlaylist>(rawText, options),
_ => JsonSerializer.Deserialize<YPlayContext>(rawText, options)
};
}
public override void Write(Utf8JsonWriter writer, YPlayContext value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, options);
}
}