public static ColorType GetXmlColorType(XElement xmlElement, string name, bool required, ColorUnitType defaultUnits) { if (xmlElement.Element(name) == null) { if (required) Messages.Add(new Message { Type = MessageType.Error, Text = String.Format("Required ColorType element '{0}' is missing.", name) }); return null; } string str = xmlElement.Element(name).Value; decimal decVal; string strUnit = str.ParseOffUnits(); ColorUnitType units = defaultUnits; try { // EBC, L, SRM if (!strUnit.IsNullOrEmpty()) units = (ColorUnitType) Enum.Parse(typeof (ColorUnitType), strUnit); } catch { Messages.Add(new Message { Type = MessageType.Error, Text = String.Format("Invalid ColorType '{0}' value or units is missing.", name) }); return null; } if (!strUnit.IsNullOrEmpty()) str = str.Replace(strUnit, null).Trim(); if (str.IsNullOrEmpty() || !Decimal.TryParse(str, out decVal)) { Messages.Add(new Message { Type = MessageType.Error, Text = String.Format("Invalid ColorType '{0}' value or units is missing.", name) }); return null; } return new ColorType {scale = units, Value = decVal}; }
private static ColorType NewColorType(decimal value, ColorUnitType colorUnits) { return new ColorType { Value = value, scale = colorUnits }; }