public override void WriteTo(XElement xE) { base.WriteTo(xE); XmlUtility.SetXsiType(xE, "https://adwords.google.com/api/adwords/cm/v201609", "TemplateAd"); XElement xItem = null; if (TemplateId != null) { xItem = new XElement(XName.Get("templateId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(TemplateId.Value.ToString()); xE.Add(xItem); } if (AdUnionId != null) { xItem = new XElement(XName.Get("adUnionId", "https://adwords.google.com/api/adwords/cm/v201609")); AdUnionId.WriteTo(xItem); xE.Add(xItem); } if (TemplateElements != null) { foreach (var templateElementsItem in TemplateElements) { xItem = new XElement(XName.Get("templateElements", "https://adwords.google.com/api/adwords/cm/v201609")); templateElementsItem.WriteTo(xItem); xE.Add(xItem); } } if (AdAsImage != null) { xItem = new XElement(XName.Get("adAsImage", "https://adwords.google.com/api/adwords/cm/v201609")); AdAsImage.WriteTo(xItem); xE.Add(xItem); } if (Dimensions != null) { xItem = new XElement(XName.Get("dimensions", "https://adwords.google.com/api/adwords/cm/v201609")); Dimensions.WriteTo(xItem); xE.Add(xItem); } if (Name != null) { xItem = new XElement(XName.Get("name", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(Name); xE.Add(xItem); } if (Duration != null) { xItem = new XElement(XName.Get("duration", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(Duration.Value.ToString()); xE.Add(xItem); } if (OriginAdId != null) { xItem = new XElement(XName.Get("originAdId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(OriginAdId.Value.ToString()); xE.Add(xItem); } }
public override void ReadFrom(XElement xE) { base.ReadFrom(xE); TemplateId = null; AdUnionId = null; TemplateElements = null; AdAsImage = null; Dimensions = null; Name = null; Duration = null; OriginAdId = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "templateId") { TemplateId = long.Parse(xItem.Value); } else if (localName == "adUnionId") { AdUnionId = InstanceCreator.CreateAdUnionId(xItem); AdUnionId.ReadFrom(xItem); } else if (localName == "templateElements") { if (TemplateElements == null) { TemplateElements = new List <TemplateElement>(); } var templateElementsItem = new TemplateElement(); templateElementsItem.ReadFrom(xItem); TemplateElements.Add(templateElementsItem); } else if (localName == "adAsImage") { AdAsImage = new Image(); AdAsImage.ReadFrom(xItem); } else if (localName == "dimensions") { Dimensions = new Dimensions(); Dimensions.ReadFrom(xItem); } else if (localName == "name") { Name = xItem.Value; } else if (localName == "duration") { Duration = int.Parse(xItem.Value); } else if (localName == "originAdId") { OriginAdId = long.Parse(xItem.Value); } } }