private void DataTolistView<T>(ListView lsit, T data) where T : IEnumerable { if (typeof(T).IsGenericType)//是否是泛型 { Type itemType = typeof(T).GetGenericArguments()[0]; var props = itemType.GetProperties(BindingFlags.Public | BindingFlags.Instance);//实体的字段列表 lsit.Columns.Clear(); lsit.Columns.Add("行"); lsit.View = View.Details ; foreach (var item in props) { lsit.Columns.Add(item.Name); } foreach (var item in data) { var id = lsit.Items.Count + 1; var row = lsit.Items.Add(id.ToString()); foreach (PropertyInfo p in props) { row.SubItems.Add(p.GetValue(item, null)?.ToString()); } } } }