public ExtraDetails MapEntitiesToObjects(IEnumerable <TWMBILLINGMORE> entities) { ExtraDetails obj = null; if (entities != null && entities.Count() > 0) { obj = new ExtraDetails(); foreach (var item in entities) { try { obj.workRequestId = item.CD_WR.ToString(); obj.district = item.CD_DIST; obj.GetType().GetProperty(item.NM_FIELD.ToString()).SetValue(obj, GetTxtValue(item), null); } catch (NullReferenceException) { //Property Does Not Exist Under ExtraDetails } } } return(obj); }
public IEnumerable <TWMBILLINGMORE> MapObjectToEntity(ExtraDetails obj) { List <TWMBILLINGMORE> entity = new List <TWMBILLINGMORE>(); foreach (System.Reflection.PropertyInfo item in new List <System.Reflection.PropertyInfo>(obj.GetType().GetProperties())) { var ent = new TWMBILLINGMORE(); ent.CD_DIST = obj.district; ent.CD_WR = Convert.ToInt64(obj.workRequestId); ent.TXT_VALUE = (string)item.GetValue(obj, null); ent.NM_FIELD = item.Name; if (item.Name != "workRequestId" && item.Name != "district") { ent.TXT_VALUE = (string)item.GetValue(obj, null); ent.NM_FIELD = item.Name; entity.Add(ent); } } return(entity); }