mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
added schema generation
This commit is contained in:
parent
e8c832ac18
commit
a66d43b806
11 changed files with 150 additions and 15 deletions
40
NzbDrone.Api/ClientSchema/SchemaBuilder.cs
Normal file
40
NzbDrone.Api/ClientSchema/SchemaBuilder.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Reflection;
|
||||
|
||||
namespace NzbDrone.Api.ClientSchema
|
||||
{
|
||||
public static class SchemaBuilder
|
||||
{
|
||||
public static List<Field> GenerateSchema(object model)
|
||||
{
|
||||
var properties = model.GetType().GetSimpleProperties();
|
||||
|
||||
var result = new List<Field>(properties.Count);
|
||||
|
||||
foreach (var propertyInfo in properties)
|
||||
{
|
||||
var fieldAttribute = propertyInfo.GetAttribute<FieldDefinitionAttribute>();
|
||||
|
||||
var field = new Field()
|
||||
{
|
||||
Name = propertyInfo.Name,
|
||||
Label = fieldAttribute.Label,
|
||||
HelpText = fieldAttribute.HelpText,
|
||||
Order = fieldAttribute.Order,
|
||||
|
||||
};
|
||||
|
||||
var value = propertyInfo.GetValue(model, null);
|
||||
if (value != null)
|
||||
{
|
||||
field.Value = value.ToString();
|
||||
}
|
||||
|
||||
result.Add(field);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue