Results parsing fixes
This commit is contained in:
1 parent
ea2ef35664
commit
502283c5d0
17 files changed
+795
-773
No files matched your search
File diff suppressed because it is too large.
Load diff
+42
-28
@@ -8,43 +8,57 @@ namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class DeclarationPatcherContractResolver : DefaultContractResolver
|
||||
{
|
||||
private readonly JsonConverter _integerConverter = new IntegerOverflowConverter();
|
||||
|
||||
private readonly ICollection<(System.Type, string)> _allowNull = new[] {
|
||||
(typeof(CommonFilmData), "ratingAgeLimits"),
|
||||
(typeof(VideoResponse_trailers), "size"),
|
||||
(typeof(Budget), null),
|
||||
};
|
||||
|
||||
private readonly ICollection<(System.Type, string, JsonConverter)> _patchConverters = new[] {
|
||||
(typeof(object), (string)null, (JsonConverter)new ProfessionKeyConverter()),
|
||||
};
|
||||
|
||||
protected override IList<JsonProperty> CreateProperties(System.Type type, MemberSerialization memberSerialization)
|
||||
{
|
||||
var list = base.CreateProperties(type, memberSerialization);
|
||||
foreach (var property in list)
|
||||
{
|
||||
if (_allowNull.Any((config) => type == config.Item1
|
||||
&& (string.IsNullOrEmpty(config.Item2) || property.PropertyName == config.Item2)))
|
||||
{
|
||||
property.Required = Required.Default;
|
||||
property.DefaultValue = -1;
|
||||
|
||||
if (_integerConverter.CanConvert(property.PropertyType))
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
property.MemberConverter = null;
|
||||
#pragma warning restore CS0618
|
||||
property.Converter = _integerConverter;
|
||||
}
|
||||
}
|
||||
|
||||
var patchConverters = _patchConverters
|
||||
.Where((config) => (config.Item1 == typeof(object) || type == config.Item1)
|
||||
&& (string.IsNullOrEmpty(config.Item2) || property.PropertyName == config.Item2))
|
||||
.ToArray();
|
||||
foreach (var patchConverter in patchConverters)
|
||||
{
|
||||
if (patchConverter.Item3.CanConvert(property.PropertyType))
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
property.MemberConverter = null;
|
||||
#pragma warning restore CS0618
|
||||
property.Converter = patchConverter.Item3;
|
||||
}
|
||||
}
|
||||
|
||||
if (property.PropertyType == typeof(string))
|
||||
{
|
||||
property.Required = Required.Default;
|
||||
}
|
||||
|
||||
if (property.PropertyType == typeof(PersonResponse_filmsProfessionKey))
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
property.MemberConverter = null;
|
||||
#pragma warning restore CS0618
|
||||
property.Converter = new ProfessionKeyConverter();
|
||||
}
|
||||
|
||||
if (type == typeof(VideoResponse_trailers))
|
||||
{
|
||||
if (property.PropertyName == "size")
|
||||
{
|
||||
property.Required = Required.Default;
|
||||
property.DefaultValue = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == typeof(Budget))
|
||||
{
|
||||
if (property.PropertyType == typeof(Int32))
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
property.MemberConverter = null;
|
||||
#pragma warning restore CS0618
|
||||
property.Converter = new IntegerOverflowConverter();
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class ProfessionKeyConverter : StringEnumConverter
|
||||
{
|
||||
public override bool CanConvert(System.Type objectType)
|
||||
=> objectType == typeof(PersonResponse_filmsProfessionKey);
|
||||
|
||||
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in new issue
Block a user