private ReleaseFormat ReadReleaseFormat(JObject source) { ReleaseFormat releaseFormat = new ReleaseFormat(); foreach (var item in source) { var v = item.Value; switch (item.Key) { case "qty": releaseFormat.Quantity = v.Value <int>(); break; case "descriptions": releaseFormat.Descriptions = v.ValueAsStringArray(); break; case "name": releaseFormat.Name = v.Value <string>(); break; case "text": releaseFormat.Text = v.Value <string>(); break; default: this.ThrowIfStrict("Unknown key: " + item.Key); break; } } return(releaseFormat); }
private ReleaseFormat ReadFormat() { this.XmlReader.AssertElementStart("format"); ReleaseFormat format = new ReleaseFormat(); format.Name = this.XmlReader.GetAttribute("name"); int quantity; if (int.TryParse(this.XmlReader.GetAttribute("qty"), out quantity)) { format.Quantity = quantity; } format.Text = this.XmlReader.GetAttribute("qty"); if (this.XmlReader.IsEmptyElement) { return(format); } while (true) { this.XmlReader.AssertRead(); if (this.XmlReader.IsElementEnd("format")) { break; } if (this.XmlReader.IsElementStart("descriptions")) { format.Descriptions = this.ReadFormatDescriptions(); } else { this.ThrowInvalidFormatException(); } } return(format); }
public static ReleaseFormat ReadReleaseFormat(XElement el) { el.AssertName("format"); ReleaseFormat result = new ReleaseFormat(); foreach (XAttribute attr in el.Attributes()) { if (attr.Name == "name") { result.Name = attr.Value; } else if (attr.Name == "qty") { result.Quantity = int.Parse(attr.Value); } else if (attr.Name == "text") { result.Text = attr.Value; } else { throw new Exception("Unknown release format attribute: " + attr.Name); } } foreach (XElement e in el.Elements()) { if (e.Name == "descriptions") { result.Descriptions = e.Elements().AssertNames("description").AssertOnlyText().Select(d => d.Value).ToArray(); } else { throw new Exception("Unknown release format element: " + e.Name); } } return(result); }
public static ReleaseFormat ReadReleaseFormat(XElement el) { el.AssertName("format"); ReleaseFormat result = new ReleaseFormat(); foreach (XAttribute attr in el.Attributes()) { if (attr.Name == "name") { result.Name = attr.Value; } else if (attr.Name == "qty") { result.Quantity = int.Parse(attr.Value); } else if (attr.Name == "text") { result.Text = attr.Value; } else { throw new Exception("Unknown release format attribute: " + attr.Name); } } foreach (XElement e in el.Elements()) { if (e.Name == "descriptions") { result.Descriptions = e.Elements().AssertNames("description").AssertOnlyText().Select(d => d.Value).ToArray(); } else { throw new Exception("Unknown release format element: " + e.Name); } } return result; }
private ReleaseFormat ReadFormat() { this.XmlReader.AssertElementStart("format"); ReleaseFormat format = new ReleaseFormat(); format.Name = this.XmlReader.GetAttribute("name"); int quantity; if (int.TryParse(this.XmlReader.GetAttribute("qty"), out quantity)) { format.Quantity = quantity; } format.Text = this.XmlReader.GetAttribute("qty"); if (this.XmlReader.IsEmptyElement) { return format; } while (true) { this.XmlReader.AssertRead(); if (this.XmlReader.IsElementEnd("format")) { break; } if (this.XmlReader.IsElementStart("descriptions")) { format.Descriptions = this.ReadFormatDescriptions(); } else { this.ThrowInvalidFormatException(); } } return format; }
private ReleaseFormat ReadReleaseFormat(JObject source) { ReleaseFormat releaseFormat = new ReleaseFormat(); foreach (var item in source) { var v = item.Value; switch (item.Key) { case "qty": releaseFormat.Quantity = v.Value<int>(); break; case "descriptions": releaseFormat.Descriptions = v.ValueAsStringArray(); break; case "name": releaseFormat.Name = v.Value<string>(); break; case "text": releaseFormat.Text = v.Value<string>(); break; default: this.ThrowIfStrict("Unknown key: " + item.Key); break; } } return releaseFormat; }