Add support for deprecated values in field select options

(cherry picked from commit d9786887f3fe30ef60ad9c50b3272bf60dfef309)

Closes #3917
pull/3919/head v1.3.2.3412
Bogdan 10 months ago
parent 04aebc4012
commit f2708937c2

@ -107,7 +107,7 @@ namespace Lidarr.Http.ClientSchema
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,33 +154,40 @@ namespace Lidarr.Http.ClientSchema
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 name = v.Name.Replace('_', ' '); var options = selectOptions
var value = Convert.ToInt32(v.GetRawConstantValue()); .GetFields()
var attrib = v.GetCustomAttribute<FieldOptionAttribute>(); .Where(v => v.IsStatic && !v.GetCustomAttributes(false).OfType<ObsoleteAttribute>().Any())
if (attrib != null) .Select(v =>
{
return new SelectOption
{
Value = value,
Name = attrib.Label ?? name,
Order = attrib.Order,
Hint = attrib.Hint ?? $"({value})"
};
}
else
{
return new SelectOption
{ {
Value = value, var name = v.Name.Replace('_', ' ');
Name = name, var value = Convert.ToInt32(v.GetRawConstantValue());
Order = value var attrib = v.GetCustomAttribute<FieldOptionAttribute>();
};
} if (attrib != null)
}); {
return new SelectOption
{
Value = value,
Name = attrib.Label ?? name,
Order = attrib.Order,
Hint = attrib.Hint ?? $"({value})"
};
}
return new SelectOption
{
Value = value,
Name = name,
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)

Loading…
Cancel
Save