Добавьте файлы проекта.

This commit is contained in:
FrigaT
2026-04-10 12:12:33 +03:00
parent 9615cf42ee
commit 11d0b0d72f
383 changed files with 9661 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
namespace YandexMusic.API.Models.Radio.Restriction
{
public sealed class YRestrictionConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return typeof(YRestriction).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);
YRestriction restriction;
try
{
YRestrictionType type = jObject["type"].ToObject<YRestrictionType>();
switch (type)
{
case YRestrictionType.Enum:
restriction = jObject.ToObject<YRestrictionEnum>();
break;
case YRestrictionType.DiscreteScale:
restriction = jObject.ToObject<YRestrictionDiscreteScale>();
break;
default:
restriction = jObject.ToObject<YRestriction>();
break;
}
}
catch (Exception ex)
{
throw new Exception($"Ошибка десериализации типа \"{objectType.Name}\".", ex);
}
return restriction;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
public class YRestriction
{
public string Name { get; set; }
public YRestrictionType Type { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace YandexMusic.API.Models.Radio.Restriction
{
public class YRestrictionDiscreteScale : YRestriction
{
public YRestrictionValue<int> Min { get; set; }
public YRestrictionValue<int> Max { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace YandexMusic.API.Models.Radio.Restriction
{
public class YRestrictionEnum : YRestriction
{
public List<YRestrictionValue<string>> PossibleValues { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using System.Runtime.Serialization;
namespace YandexMusic.API.Models.Radio.Restriction
{
[JsonConverter(typeof(StringEnumConverter))]
public enum YRestrictionType
{
[EnumMember(Value = "discrete-scale")]
DiscreteScale,
Enum
}
}

View File

@@ -0,0 +1,8 @@
namespace YandexMusic.API.Models.Radio.Restriction
{
public class YRestrictionValue<T>
{
public string Name { get; set; }
public T Value { get; set; }
}
}