-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataTableSchemaCreator.cs
40 lines (33 loc) · 1.18 KB
/
DataTableSchemaCreator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using CompleteSQL.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace CompleteSQL
{
public class DataTableSchemaCreator
{
public DataTableSchema CreateSchema<T>(string tableName)
{
PropertyInfo[] props = typeof(T).GetProperties();
bool b = props[0].GetGetMethod().IsPublic;
List<DataColumnSchema> columnSchemaList = new List<DataColumnSchema>();
foreach(PropertyInfo prop in typeof(T).GetProperties(BindingFlags.Public| BindingFlags.Instance))
{
columnSchemaList.Add(new DataColumnSchema(prop.Name, prop.PropertyType));
}
if (string.IsNullOrWhiteSpace(tableName))
{
tableName = (new SqlTableNameMapper()).GetFullTableName(typeof(T)).ToString();
}
return new DataTableSchema(tableName, columnSchemaList);
}
public DataTableSchema CreateSchema<T>()
{
string tableName = typeof(T).Name;
return CreateSchema<T>(tableName);
}
}
}