private static void ShowComponentInfo(IGiftComponent giftComponent, int i) { Console.WriteLine("-----------------------------"); Console.WriteLine("{0}.{1} {2} {3} \n Weight: {4}, Net weight: {5} ", i, giftComponent, giftComponent.Name, giftComponent.CompanyName, giftComponent.Weight, giftComponent.NetWeight); var contentInfo = string.Format(" Sugar: {0} ", giftComponent.Sugar); var chocolateComponent = giftComponent as IChocolate; if (chocolateComponent != null) { contentInfo += "Chocolate: " + chocolateComponent.Chocolate; } Console.WriteLine(contentInfo); Console.WriteLine(" Wrapper: {0}", giftComponent.Wrapper != null ? giftComponent.Wrapper.WrapperType.ToString() : "missing"); Console.WriteLine(); }
private static void AddGiftComponentPart(IGiftComponent giftComponent, XElement element) { if (giftComponent.Weight != 0) { element.Add(new XElement("Weight", giftComponent.Weight)); } if (giftComponent.Sugar != 0) { element.Add(new XElement("Sugar", giftComponent.Sugar)); } if (!string.IsNullOrEmpty(giftComponent.Name)) { element.Add(new XElement("Name", giftComponent.Name)); } if (!string.IsNullOrEmpty(giftComponent.CompanyName)) { element.Add(new XElement("CompanyName", giftComponent.CompanyName)); } element.Add(new XAttribute("MakingType", giftComponent.MakingType)); if (giftComponent.Wrapper != null) { element.Add(new XElement("Wrapper", new XAttribute("WrapperType", giftComponent.Wrapper.WrapperType), new XElement("Weight", giftComponent.Wrapper.Weight))); } }