Добавьте файлы проекта.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
namespace YandexMusic.API.Models.Landing.Entity.Entities.Context
|
||||
{
|
||||
public sealed class YPlayContextConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return typeof(YLandingEntity).IsAssignableFrom(objectType);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
return null;
|
||||
|
||||
JObject jObject = JObject.Load(reader);
|
||||
|
||||
YPlayContext context;
|
||||
try
|
||||
{
|
||||
YPlayContextType type = jObject["context"].ToObject<YPlayContextType>();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case YPlayContextType.Album:
|
||||
context = jObject.ToObject<YPlayContextAlbum>();
|
||||
break;
|
||||
case YPlayContextType.Artist:
|
||||
context = jObject.ToObject<YPlayContextArtist>();
|
||||
break;
|
||||
case YPlayContextType.Playlist:
|
||||
context = jObject.ToObject<YPlayContextPlaylist>();
|
||||
break;
|
||||
default:
|
||||
context = jObject.ToObject<YPlayContext>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Ошибка десериализации типа \"{jObject["type"]}\".", ex);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class YPlayContext
|
||||
{
|
||||
public string Client { get; set; }
|
||||
public YPlayContextType Context { get; set; }
|
||||
public string ContextItem { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using YandexMusic.API.Models.Album;
|
||||
|
||||
namespace YandexMusic.API.Models.Landing.Entity.Entities.Context
|
||||
{
|
||||
public class YPlayContextAlbum : YPlayContext
|
||||
{
|
||||
public YAlbum Payload { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using YandexMusic.API.Models.Artist;
|
||||
|
||||
namespace YandexMusic.API.Models.Landing.Entity.Entities.Context
|
||||
{
|
||||
public class YPlayContextArtist : YPlayContext
|
||||
{
|
||||
public YArtist Payload { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using YandexMusic.API.Models.Playlist;
|
||||
|
||||
namespace YandexMusic.API.Models.Landing.Entity.Entities.Context
|
||||
{
|
||||
public class YPlayContextPlaylist : YPlayContext
|
||||
{
|
||||
public YPlaylist Payload { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace YandexMusic.API.Models.Landing.Entity.Entities.Context
|
||||
{
|
||||
public enum YPlayContextType
|
||||
{
|
||||
Album,
|
||||
Artist,
|
||||
Playlist
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user