public static Partner Partner(RpcRecord saleOrderRecord) { var street = (string)saleOrderRecord.GetField("street").Value; var name = (string)saleOrderRecord.GetField("name").Value; var parter = new Partner() { Street = street, Name = name }; return(parter); }
public static SaleOrder SaleOrder(RpcRecord saleOrderRecord) { var company = (int)saleOrderRecord.GetField("company_id").Value; var name = (string)saleOrderRecord.GetField("name").Value; var saleOrder = new SaleOrder() { CompanyId = company, Name = name }; return(saleOrder); }
public static TEntity ToEntity <TEntity>(this RpcRecord record) where TEntity : class { var entity = (TEntity)Activator.CreateInstance(typeof(TEntity)); foreach (PropertyInfo prop in entity.GetType().GetProperties()) { var propName = prop.Name.ToLowerAndSplitWithUnderscore(); var value = record.GetField(propName).Value; if (value == null) { prop.SetValue(entity, value); } else if (prop.PropertyType == typeof(DateTime) || prop.PropertyType == typeof(DateTime?)) { prop.SetValue(entity, Convert.ToDateTime(value)); } else if (value.GetType() == typeof(object[])) { var values = value as object[]; var valueId = values[0]; prop.SetValue(entity, valueId); } else { prop.SetValue(entity, value); } } return(entity); }