コード例 #1
0
        public static DataTable CreateTable <T>()
        {
            Type entityType = typeof(T);
            var  table      = new DataTable(entityType.Name);
            var  properties = TypeDescriptor.GetProperties(entityType);

            foreach (PropertyDescriptor prop in properties)
            {
                // respect nullable types
                Type type = ConvertExtensions.IsNullable(prop.PropertyType)
                                        ? Nullable.GetUnderlyingType(prop.PropertyType)
                                        : prop.PropertyType;

                table.Columns.Add(prop.Name, type);
            }

            return(table);
        }