using System.Collections.Generic;
using System.ComponentModel;
public static void Main()
DataTable dt = new List<Photos> { new Photos { Name = "Item 1", Model = "Model 1" } }
FiddleHelper.WriteTable(dt);
public static class IListExtensions
public static DataTable ToDataTable<T>(this IList<T> list)
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
DataTable dataTable = new DataTable();
foreach (PropertyDescriptor property in properties)
dataTable.Columns.Add(property.Name, Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType);
DataRow row = dataTable.NewRow();
foreach (PropertyDescriptor property in properties)
row[property.Name] = property.GetValue(item) ?? DBNull.Value;
public string Name { get; set; }
public string Model { get; set; }