|
@ -536,6 +536,37 @@ namespace SqlSugar |
|
|
} |
|
|
} |
|
|
return this.DeserializeObject<List<T>>(this.SerializeObject(deserializeObject)); |
|
|
return this.DeserializeObject<List<T>>(this.SerializeObject(deserializeObject)); |
|
|
} |
|
|
} |
|
|
|
|
|
public DataTable ListToDataTable<T>(List<T> list) |
|
|
|
|
|
{ |
|
|
|
|
|
DataTable result = new DataTable(); |
|
|
|
|
|
if (list.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
PropertyInfo[] propertys = list[0].GetType().GetProperties(); |
|
|
|
|
|
foreach (PropertyInfo pi in propertys) |
|
|
|
|
|
{ |
|
|
|
|
|
//获取类型
|
|
|
|
|
|
Type colType = pi.PropertyType; |
|
|
|
|
|
//当类型为Nullable<>时
|
|
|
|
|
|
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>))) |
|
|
|
|
|
{ |
|
|
|
|
|
colType = colType.GetGenericArguments()[0]; |
|
|
|
|
|
} |
|
|
|
|
|
result.Columns.Add(pi.Name, colType); |
|
|
|
|
|
} |
|
|
|
|
|
for (int i = 0; i < list.Count; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
ArrayList tempList = new ArrayList(); |
|
|
|
|
|
foreach (PropertyInfo pi in propertys) |
|
|
|
|
|
{ |
|
|
|
|
|
object obj = pi.GetValue(list[i], null); |
|
|
|
|
|
tempList.Add(obj); |
|
|
|
|
|
} |
|
|
|
|
|
object[] array = tempList.ToArray(); |
|
|
|
|
|
result.LoadDataRow(array, true); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
public Dictionary<string, object> DataTableToDictionary(DataTable table) |
|
|
public Dictionary<string, object> DataTableToDictionary(DataTable table) |
|
|
{ |
|
|
{ |
|
|
return table.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1]); |
|
|
return table.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1]); |
|
|