mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-29 11:16:19 +00:00
38 lines
No EOL
1.1 KiB
C#
38 lines
No EOL
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using NzbDrone.Common.Reflection;
|
|
using NzbDrone.Core.Annotations;
|
|
|
|
namespace NzbDrone.Api.ClientSchema
|
|
{
|
|
public static class SchemaDeserializer
|
|
{
|
|
public static object DeserializeSchema(object model, List<Field> fields)
|
|
{
|
|
var properties = model.GetType().GetSimpleProperties();
|
|
|
|
foreach (var propertyInfo in properties)
|
|
{
|
|
var fieldAttribute = propertyInfo.GetAttribute<FieldDefinitionAttribute>(false);
|
|
|
|
if (fieldAttribute != null)
|
|
{
|
|
var field = fields.Find(f => f.Name == propertyInfo.Name);
|
|
|
|
if (propertyInfo.PropertyType == typeof (Int32))
|
|
{
|
|
var intValue = Convert.ToInt32(field.Value);
|
|
propertyInfo.SetValue(model, intValue, null);
|
|
}
|
|
|
|
else
|
|
{
|
|
propertyInfo.SetValue(model, field.Value, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
return model;
|
|
}
|
|
}
|
|
} |