public void LoadFromDynamicDictionary(DynamicDictionary item) { ModelBase model = this; PropertyInfo prop; List <PropertyInfo> FieldList = model.GetFieldList(); for (int i = 0, len = FieldList.Count; i < len; i++) { prop = FieldList[i]; if (item.ContainsKey(prop.Name.Trim().ToLower())) { if (item[prop.Name.Trim().ToLower()] == null) { prop.SetValue(model, null); } else { try { //prop.SetValue(model, ModelService.ChangeType(item[prop.Name.Trim().ToLower()], prop.PropertyType)); prop.SetValue(model, ModelService.ChangeType(item.GetValue(prop.Name.Trim().ToLower()), prop.PropertyType)); } catch (Exception ex) { prop.SetValue(model, null); } } } } }
public void LoadFromDataRow(DataRow dr) { DataColumnCollection columns = dr.Table.Columns; ModelBase model = this; PropertyInfo prop; List <PropertyInfo> FieldList = model.GetFieldList(); for (int i = 0, len = FieldList.Count; i < len; i++) { prop = FieldList[i]; if (dr.Table.Columns.Contains(prop.Name)) { if (dr[prop.Name].GetType() == typeof(DBNull)) { prop.SetValue(model, null); } else { prop.SetValue(model, ModelService.ChangeType(dr[prop.Name], prop.PropertyType)); //prop.SetValue(this, Convert.ChangeType(dr[prop.Name], prop.PropertyType)); } } } }