/// <summary> /// Deserializes the provided <see cref="XElement"/>. /// </summary> /// <param name="element">Required. The <see cref="XElement"/> to deserialize.</param> /// <returns><see cref="RelationAttribute"/>.</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() != "RelationAttribute")) { throw new InvalidOperationException("Not a valid RelationAttribute."); } var relationAttribute = new RelationAttribute { Name = (string)element.Attribute("name"), Values = new List <string>( element.Descendants("Value").Select(d => d.Value) ) }; if (!string.IsNullOrEmpty((string)element.Attribute("nameParserClass"))) { relationAttribute.NameParserClass = (string)element.Attribute("nameParserClass"); } if (!string.IsNullOrEmpty((string)element.Attribute("id"))) { relationAttribute.DefinitionId = int.Parse((string)element.Attribute("id")); } return(relationAttribute); }
/// <summary> /// Factory method for instantiating a new instance of a <see cref="RelationAttribute"/> with the provided parameters set. /// </summary> /// <param name="name">The name of the attribute</param> /// <param name="values">The values of the attribute.</param> /// <param name="definitionId">The definition id of the attribute.</param> /// <param name="nameParserClass">Optional.</param> /// <returns><see cref="RelationAttribute"/></returns> public static RelationAttribute New(string name, IEnumerable <string> values, int definitionId = -1, string nameParserClass = null) { var relationAttribute = new RelationAttribute(name, definitionId, nameParserClass); if (values != null && values.Count() >= 1) { relationAttribute.Values.AddRange(values); } return(relationAttribute); }
/// <summary> /// Factory method for instantiating a new instance of a <see cref="RelationAttribute"/> with the provided parameters set. /// </summary> /// <param name="name">The name of the attribute</param> /// <param name="value">The value of the attribute.</param> /// <param name="definitionId">The definition id of the attribute.</param> /// <param name="nameParserClass">Optional.</param> /// <returns><see cref="RelationAttribute"/></returns> public static RelationAttribute New(string name, string value, int definitionId = -1, string nameParserClass = null) { var relationAttribute = new RelationAttribute(name, definitionId, nameParserClass); if (value != null) { relationAttribute.Values.Add(value); } return(relationAttribute); }