private static ProductColor[] XmlToProductColors(XElement ele) { if (ele.Element("Colors") == null) { return(null); } IEnumerable <XElement> eles = ele.Element("Colors").Elements("Color"); if (eles == null || eles.Count() == 0) { return(null); } List <ProductColor> colors = new List <ProductColor>(); ProductColor color = null; foreach (XElement element in eles) { color = XmlToProductColor(element); if (color != null) { colors.Add(color); } } return(colors == null ? null : colors.ToArray()); }
private static ProductColor XmlToProductColor(XElement ele) { if (ele == null) { return(null); } ProductColor color = new ProductColor(); IEnumerable <XAttribute> atts = ele.Attributes(); foreach (XAttribute att in atts) { switch (att.Name.ToString().ToLower()) { case "color": if (!String.IsNullOrEmpty(att.Value)) { color.Color = StringToColor(att.Value); } break; case "maxvalue": if (!String.IsNullOrEmpty(att.Value)) { color.MaxValue = float.Parse(att.Value); } else { color.MaxValue = float.MaxValue; } break; case "minvalue": if (!String.IsNullOrEmpty(att.Value)) { color.MinValue = float.Parse(att.Value); } else { color.MinValue = float.MinValue; } break; case "labeltext": color.LableText = string.IsNullOrWhiteSpace(att.Value) ? "" : att.Value; break; case "displaylengend": color.DisplayLengend = att.Value != null && att.Value.ToUpper() == "TRUE"; break; } } return(color); }