public EdiFile ToEdiFile() { EdiFile result = new EdiFile(firmId); EdiTable actorsTable = EdiModel.EdiTableFor <Actor>(); foreach (Actor actor in actors) { actorsTable.Add(actor.ToEdiRow()); } result.Add(actorsTable); foreach (Order order in orders) { EdiTable orderTable = EdiModel.EdiTableFor <Order>(); orderTable.Add(order.ToEdiRow()); result.Add(orderTable); EdiTable orderLineTable = EdiModel.EdiTableFor <OrderLine>(); foreach (OrderLine orderline in order.OrderLines) { orderLineTable.Add(orderline.ToEdiRow()); } result.Add(orderLineTable); } result.RemoveUnusedFields(); return(result); }
public static EdiTable EdiTableFor <T>() where T : EdiModel { String name = typeof(T).Name; bool identifyByFirst = false; System.Attribute[] attrs = System.Attribute.GetCustomAttributes(typeof(T)); EdiElementAttribute ediElementAttr = attrs .Where(x => x is EdiElementAttribute) .Select(x => x as EdiElementAttribute) .FirstOrDefault(); if (ediElementAttr != null) { if (ediElementAttr.Name != null) { name = ediElementAttr.Name; } identifyByFirst = ediElementAttr.IdentifyByFirst; } EdiTable table = new EdiTable(name); table.ImportMethod = identifyByFirst ? 1 : 3; foreach (PropertyInfo p in typeof(T).GetProperties()) { if (p.PropertyType != typeof(String)) { continue; } table.AddHeader(p.Name); } return(table); }