using Telerik.WinControls.UI; namespace Pilz.UI.WinForms.Telerik.Extensions; public static class RadListDataItemCollectionExtensions { public static IEnumerable AddEnumValues(this RadListDataItemCollection @this) where T : struct, Enum { return @this.AddEnumValues(false); } public static IEnumerable AddEnumValues(this RadListDataItemCollection @this, bool clearCollection) where T : struct, Enum { return @this.AddEnumValues(clearCollection, null, null); } public static IEnumerable AddEnumValues(this RadListDataItemCollection @this, bool clearCollection, Func? filter, Func? format) where T : struct, Enum { var values = Enum.GetValues(typeof(T)); var items = new List(); format ??= v => Enum.GetName(typeof(T), v); if (clearCollection) @this.Clear(); foreach (T value in values) { if (filter is null || filter(value)) items.Add(new(format(value), value)); } @this.AddRange(items); return items; } }