1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-23 00:03:05 +00:00

Add support for deprecated values in field select options

(cherry picked from commit d9786887f3fe30ef60ad9c50b3272bf60dfef309)

Closes #3917
This commit is contained in:
Bogdan 2023-07-21 00:49:58 +03:00
parent 04aebc4012
commit f2708937c2

View file

@ -107,7 +107,7 @@ private static FieldMapping[] GetFieldMapping(Type type, string prefix, Func<obj
Placeholder = fieldAttribute.Placeholder Placeholder = fieldAttribute.Placeholder
}; };
if (fieldAttribute.Type == FieldType.Select || fieldAttribute.Type == FieldType.TagSelect) if (fieldAttribute.Type is FieldType.Select or FieldType.TagSelect)
{ {
if (fieldAttribute.SelectOptionsProviderAction.IsNotNullOrWhiteSpace()) if (fieldAttribute.SelectOptionsProviderAction.IsNotNullOrWhiteSpace())
{ {
@ -154,11 +154,17 @@ private static Tuple<PropertyInfo, FieldDefinitionAttribute>[] GetProperties(Typ
private static List<SelectOption> GetSelectOptions(Type selectOptions) private static List<SelectOption> GetSelectOptions(Type selectOptions)
{ {
var options = selectOptions.GetFields().Where(v => v.IsStatic).Select(v => if (selectOptions.IsEnum)
{
var options = selectOptions
.GetFields()
.Where(v => v.IsStatic && !v.GetCustomAttributes(false).OfType<ObsoleteAttribute>().Any())
.Select(v =>
{ {
var name = v.Name.Replace('_', ' '); var name = v.Name.Replace('_', ' ');
var value = Convert.ToInt32(v.GetRawConstantValue()); var value = Convert.ToInt32(v.GetRawConstantValue());
var attrib = v.GetCustomAttribute<FieldOptionAttribute>(); var attrib = v.GetCustomAttribute<FieldOptionAttribute>();
if (attrib != null) if (attrib != null)
{ {
return new SelectOption return new SelectOption
@ -169,20 +175,21 @@ private static List<SelectOption> GetSelectOptions(Type selectOptions)
Hint = attrib.Hint ?? $"({value})" Hint = attrib.Hint ?? $"({value})"
}; };
} }
else
{
return new SelectOption return new SelectOption
{ {
Value = value, Value = value,
Name = name, Name = name,
Order = value Order = value
}; };
}
}); });
return options.OrderBy(o => o.Order).ToList(); return options.OrderBy(o => o.Order).ToList();
} }
throw new NotSupportedException();
}
private static Func<object, object> GetValueConverter(Type propertyType) private static Func<object, object> GetValueConverter(Type propertyType)
{ {
if (propertyType == typeof(int)) if (propertyType == typeof(int))