Tag: 集合数据表可以为

.NET – 将通用集合转换为DataTable

我正在尝试将generics集合(List)转换为DataTable。 我发现下面的代码来帮助我做到这一点: // Sorry about indentation public class CollectionHelper { private CollectionHelper() { } // this is the method I have been using public static DataTable ConvertTo<T>(IList<T> list) { DataTable table = CreateTable<T>(); Type entityType = typeof(T); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType); foreach (T item in list) { DataRow row = table.NewRow(); foreach (PropertyDescriptor prop in […]