CloudBuilder/CloudBuilder.Gui/KryptonListItemConvertor.cs
owenchen 1c0c83af5f ow
2026-05-12 10:09:31 +08:00

51 lines
1.5 KiB
C#

using Krypton.Toolkit;
using System.Reflection;
namespace System
{
public static class KryptonListItemConvertor
{
public static KryptonListItem[] ToKryptonListItem<T>(IList<T> list, string display, string value)
{
if (list == null || list.Count == 0) return null;
List<KryptonListItem> l = new List<KryptonListItem>();
KryptonListItem kryptonListItem;
Type elementType = typeof(T);
int i = 0;
Dictionary<int, object> keyValues = new Dictionary<int, object>();
foreach (T item in list)
{
kryptonListItem = new KryptonListItem();
foreach (PropertyInfo property in elementType.GetProperties())
{
if (property.Name == display)
{
kryptonListItem.ShortText = property.GetValue(item, null).ToString();
l.Add(kryptonListItem);
}
if (property.Name == value)
{
keyValues.Add(i, property.GetValue(item, null));
}
}
kryptonListItem.Tag = keyValues;
i++;
}
return l.ToArray();
}
public static KryptonListItem[] ToKryptonListItem<T>(T[] list, string display, string value)
{
if (list == null || list.Length == 0) return null;
return ToKryptonListItem<T>(list.ToList(), display, value);
}
}
}