/// <summary> /// Deserializes the provided <see cref="XElement"/>. /// </summary> /// <param name="element">Required. The <see cref="XElement"/> to deserialize.</param> /// <returns><see cref="SimpleAttribute"/>.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="element"/> is null.</exception> public IAdsmlAttribute Deserialize(XElement element) { if (element == null) { throw new ArgumentNullException("element"); } if ((string.IsNullOrEmpty(element.Name.ToString()) || element.Name.ToString() != "SimpleAttribute")) { throw new InvalidOperationException("Not a valid SimpleAttribute."); } var type = (string)element.Attribute("type"); type = type.Capitalize(); var simpleAttribute = new SimpleAttribute((AttributeTypes)Enum.Parse(typeof(AttributeTypes), type)) { Name = (string)element.Attribute("name"), Values = new List <string>( element.Descendants("Value").Select(d => d.Value) ) }; return(simpleAttribute); }
/// <summary> /// Factory method to create a new instance of <see cref="SimpleAttribute"/> with the provided parameters set. /// </summary> /// <param name="attributeType">The datatype of attribute.</param> /// <param name="attributeName">The name of the attribute.</param> /// <param name="value">The value of the attribute.</param> /// <returns><see cref="SimpleAttribute"/></returns> public static SimpleAttribute New(AttributeTypes attributeType, string attributeName, string value = null) { var simpleAttribute = new SimpleAttribute(attributeType) { Name = attributeName }; if (value != null) { simpleAttribute.Values.Add(value); } return(simpleAttribute); }
/// <summary> /// Factory method to create a new instance of <see cref="SimpleAttribute"/> with the provided parameters set. /// </summary> /// <param name="attributeType">The datatype of attribute.</param> /// <param name="attributeName">The name of the attribute.</param> /// <param name="values">The values of the attribute.</param> /// <returns><see cref="SimpleAttribute"/></returns> public static SimpleAttribute New(AttributeTypes attributeType, string attributeName, IEnumerable <string> values) { var simpleAttribute = new SimpleAttribute(attributeType) { Name = attributeName }; var tmp = values.ToList(); if (tmp.Count() >= 1) { simpleAttribute.Values.AddRange(tmp); } return(simpleAttribute); }