using System; using System.Collections.Generic; using System.Linq; using NetTopologySuite.Features; namespace Deltares.Maps { public class AttributesDictionary : IAttributesTable { private readonly Dictionary attributes; public AttributesDictionary() { attributes = new Dictionary(); } #region Implementation of IAttributesTable static void ThrowArgumentNullExceptionWhenAttributeIsNullOrEmpty(string attributeName) { if (string.IsNullOrEmpty(attributeName)) { throw new ArgumentNullException("attributeName"); } } public void AddAttribute(string attributeName, object value) { ThrowArgumentNullExceptionWhenAttributeIsNullOrEmpty(attributeName); if (value == null) { throw new ArgumentNullException("value"); } string attrName = attributeName.ToUpper(); attributes.Add(attrName, value); } public void DeleteAttribute(string attributeName) { ThrowArgumentNullExceptionWhenAttributeIsNullOrEmpty(attributeName); string attrName = attributeName.ToUpper(); if (attributes.ContainsKey(attrName)) { attributes.Remove(attrName); } } public Type GetType(string attributeName) { ThrowArgumentNullExceptionWhenAttributeIsNullOrEmpty(attributeName); string attrName = attributeName.ToUpper(); return this[attrName].GetType(); } public bool Exists(string attributeName) { ThrowArgumentNullExceptionWhenAttributeIsNullOrEmpty(attributeName); string attrName = attributeName.ToUpper(); return attributes.ContainsKey(attrName); } public string[] GetNames() { return attributes.Keys.Select(key => key.ToUpper()).ToArray(); } public object[] GetValues() { return attributes.Values.ToArray(); } public object this[string attributeName] { get { ThrowArgumentNullExceptionWhenAttributeIsNullOrEmpty(attributeName); string attrName = attributeName.ToUpper(); return attributes[attrName]; } set { ThrowArgumentNullExceptionWhenAttributeIsNullOrEmpty(attributeName); string attrName = attributeName.ToUpper(); attributes[attrName] = value; } } public int Count { get { return attributes.Count; } } #endregion } }