// ----------------------------------------------------------------------- // // TODO: Update copyright text. // // ----------------------------------------------------------------------- namespace OsmReader.OsmData.Elements { using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; /// /// TODO: Update summary. /// public abstract class AbstractTaggedOsmElement { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] [XmlElement(ElementName = "tag")] public List tag { get; set; } [XmlIgnore] public string Name { get { return getTagValue("name"); } } private Dictionary tags = null; [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "int")] protected int getIntTagValue(string key) { string valueStr = getTagValue(key); int val = 0; if (!string.IsNullOrEmpty(valueStr)) { try { val = int.Parse(valueStr); } catch { } } return val; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "bool")] protected bool getBoolTagValue(string key) { string valueStr = getTagValue(key); bool val = false; if (!string.IsNullOrEmpty(valueStr)) { valueStr = valueStr.ToUpperInvariant(); try { val = bool.Parse(valueStr); } catch { switch (valueStr) { case "TRUE": case "ON": case "YES": val = true; break; default: val = false; break; } } } return val; } protected string getTagValue(string key) { string val = null; if (tag != null) { if (this.tags == null) { this.tags = new Dictionary(); foreach (OsmTag t1 in tag) { this.tags.Add(t1.key, t1.value); } } if (this.tags.ContainsKey(key)) { val = this.tags[key]; } } return val; } } }