<summary>///reflection gets the field name and value of the entity class///var dict = GetProperties (model); </summary>///<typeparam name= "T" > entity class </typeparam>///<param name= "T" > Instantiation </param>/ <returns></returns> public static Dictionary<object, object> getproperties<t> (T t) {var ret =
New Dictionary<object, object> ();
if (t = = null) {return null;} Propertyinfo[] Properties = T.gettype (). GetProperties (BindingFlags.Instance |
BindingFlags.Public); if (properties.
Length <= 0) {return null;} foreach (PropertyInfo item in properties) {string name = Item.
Name; Object value = Item.
GetValue (t, NULL); if (item. Propertytype.isvaluetype | | Item. PropertyType.Name.StartsWith ("String")) {ret.
ADD (name, value);
} return ret; ///Get Entity class field name and field value RBAC by reflection. Model.sy_admin model = new RBAC.
Model.sy_admin ();
var dict = GetProperties (model); foreach (var item in dict) {str = string. Format ("{0}-----{1}<br/>", item. Key, item.
Value); }
/* Ilist<model1> T1 = datatabletolist<model1> (DT); * *///<summary>///DataTable populate entity classes with generics///</summary>///<typeparam name= "T" > Entity class </typeparam>///<param name= "table" >dt</param>///<returns></return s> public static ilist<t> datatabletolist<t> (DataTable table) {ilist<t>
List = new list<t> ();
T t = default (t);
propertyinfo[] propertypes = null; String tempname = String.
Empty; foreach (DataRow row in table).
Rows) {t = activator.createinstance<t> (); Propertypes = T.gettype ().
GetProperties (); foreach (PropertyInfo Pro in propertypes) {tempname = Pro.
Name; if (table.
Columns.contains (Tempname)) { Object value = MscL. Until.isnullordbnull (Row[tempname])?
Null:row[tempname]; Pro.
SetValue (t, value, NULL); } list.
ADD (t);
} return list; }