UsingSystem. Data;
UsingSystem. Collections. Generic;
# RegionConvert ilist <t> to Dataset
/// <Summary>
/// Converts to data set.
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
/// <Param name = "list"> the list. </param>
/// <Returns> </returns>
Public StaticDataset converttodataset <t> (ilist <t> List)
{
If(List =Null| List. Count <= 0)
{
Return Null;
}
Dataset DS =NewDataset ();
Datatable dt =NewDatatable (Typeof(T). Name );
Datacolumn column;
Datarow row;
System. reflection. propertyinfo [] mypropertyinfo =Typeof(T). getproperties (system. reflection. bindingflags. Public | system. reflection. bindingflags. instance );
Foreach(TInList)
{
If(T =Null)
{
Continue;
}
Row = DT. newrow ();
For(IntI = 0, j = mypropertyinfo. length; I <j; I ++)
{
System. reflection. propertyinfo Pi = mypropertyinfo [I];
StringName = pi. Name;
If(Dt. Columns [name] =Null)
{
Column =NewDatacolumn (name, Pi. propertytype );
DT. Columns. Add (column );
}
Row [name] = pi. getvalue (t,Null);
}
DT. Rows. Add (ROW );
}
DS. Tables. Add (DT );
ReturnDS;
}
# Endregion