Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/Assemblers/DtoPropertyAttributeMap.cs =================================================================== diff -u -r3893 -r4000 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/Assemblers/DtoPropertyAttributeMap.cs (.../DtoPropertyAttributeMap.cs) (revision 3893) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/Assemblers/DtoPropertyAttributeMap.cs (.../DtoPropertyAttributeMap.cs) (revision 4000) @@ -36,6 +36,162 @@ /// private readonly IDictionary dict = new Dictionary(); + /// + /// Adds a property attribute mapping to the dictionary + /// + /// The item to add + public void Add(DtoPropertyAttributeMapping item) + { + if (item == null) + { + throw new ArgumentNullException("item"); + } + + Add(item.PropertyName, item); + } + + /// + /// Adds a or updtes a property attribute mapping to the dictionary + /// + /// The item to add + public void AddOrUpdate(string propName, string attrName) + { + AddOrUpdate(propName, attrName, DtoPropertyImportance.Optional); + } + + /// + /// Adds a or updtes a property attribute mapping to the dictionary + /// + /// The item to add + public void AddOrUpdate(string propName, string attrName, DtoPropertyImportance importance) + { + if (!attrName.HasValidStringValue()) + { + throw new DtoPropertyMapException("attrName"); + } + + AddOrUpdate(propName, + new DtoPropertyAttributeMapping + { + PropertyName = propName, + AttributeName = attrName, + Importance = importance + }); + } + + /// + /// Adds a or updtes a property attribute mapping to the dictionary + /// + /// The item to add + public void AddOrUpdate(DtoPropertyAttributeMapping item) + { + if (item == null) + { + throw new ArgumentNullException("item"); + } + + AddOrUpdate(item.PropertyName, item); + } + + /// + /// Adds or updates new items in the dictionary + /// + /// The name of the property + /// The value + public void AddOrUpdate(string propName, DtoPropertyAttributeMapping item) + { + if (item == null) + { + throw new ArgumentNullException("item"); + } + + if (!propName.HasValidStringValue()) + { + throw new DtoPropertyMapException("Property name (or key) is empty"); + } + + if (!dict.ContainsKey(propName)) + { + Add(item.PropertyName, item); + } + else + { + dict[propName] = item; + } + } + + /// + /// Adds or updates new items in the dictionary + /// + /// The key value pair collection to handle + public void AddOrUpdateRange(IEnumerable coll) + { + foreach (DtoPropertyAttributeMapping item in coll) + { + AddOrUpdate(item); + } + } + + /// + /// Gets an item by property name + /// + /// The name of the property to look for + /// The item if found null otherwise + public DtoPropertyAttributeMapping GetByPropertyName(string name) + { + return GetByPropertyName(name, StringComparison.InvariantCultureIgnoreCase); + } + + /// + /// Gets an item by property name + /// + /// The name of the property to look for + /// The string type + /// The item if found null otherwise + public DtoPropertyAttributeMapping GetByPropertyName(string name, StringComparison comparisonType) + { + IEnumerable q = from x in dict.Values + where x.PropertyName.Equals(name, comparisonType) + select x; + + if (q.Any()) + { + return q.Single(); + } + + return null; + } + + /// + /// Gets an item by attribute name + /// + /// The name of the property to look for + /// The item if found null otherwise + public DtoPropertyAttributeMapping GetByAttributeName(string name) + { + return GetByAttributeName(name, StringComparison.InvariantCultureIgnoreCase); + } + + /// + /// Gets an item by attribute name + /// + /// The name of the property to look for + /// The string type + /// The item if found null otherwise + public DtoPropertyAttributeMapping GetByAttributeName(string name, StringComparison comparisonType) + { + IEnumerable q = from x in dict.Values + where x.AttributeName.Equals(name, comparisonType) + select x; + + if (q.Any()) + { + return q.Single(); + } + + return null; + } + #region IDictionary Members /// @@ -46,10 +202,14 @@ public void Add(string propName, DtoPropertyAttributeMapping item) { if (item == null) + { throw new DtoPropertyMapException("Cannot add an empty or null item to the map"); + } if (!item.PropertyName.HasValidStringValue() || propName != item.PropertyName) + { throw new DtoPropertyMapException("Property name is empty or doesn't match dictionary property name (key)"); + } dict.Add(propName, item); } @@ -69,7 +229,10 @@ /// public ICollection Keys { - get { return dict.Keys; } + get + { + return dict.Keys; + } } /// @@ -98,7 +261,10 @@ /// public ICollection Values { - get { return dict.Values; } + get + { + return dict.Values; + } } /// @@ -108,8 +274,14 @@ /// public DtoPropertyAttributeMapping this[string propName] { - get { return dict[propName]; } - set { dict[propName] = value; } + get + { + return dict[propName]; + } + set + { + dict[propName] = value; + } } /// @@ -188,149 +360,5 @@ } #endregion - - /// - /// Adds a property attribute mapping to the dictionary - /// - /// The item to add - public void Add(DtoPropertyAttributeMapping item) - { - if (item == null) - throw new ArgumentNullException("item"); - - Add(item.PropertyName, item); - } - - /// - /// Adds a or updtes a property attribute mapping to the dictionary - /// - /// The item to add - public void AddOrUpdate(string propName, string attrName) - { - AddOrUpdate(propName, attrName, DtoPropertyImportance.Optional); - } - - /// - /// Adds a or updtes a property attribute mapping to the dictionary - /// - /// The item to add - public void AddOrUpdate(string propName, string attrName, DtoPropertyImportance importance) - { - if (!attrName.HasValidStringValue()) - throw new DtoPropertyMapException("attrName"); - - AddOrUpdate(propName, - new DtoPropertyAttributeMapping() - { - PropertyName = propName, - AttributeName = attrName, - Importance = importance - }); - } - - - /// - /// Adds a or updtes a property attribute mapping to the dictionary - /// - /// The item to add - public void AddOrUpdate(DtoPropertyAttributeMapping item) - { - if (item == null) - throw new ArgumentNullException("item"); - - AddOrUpdate(item.PropertyName, item); - } - - - /// - /// Adds or updates new items in the dictionary - /// - /// The name of the property - /// The value - public void AddOrUpdate(string propName, DtoPropertyAttributeMapping item) - { - if (item == null) - throw new ArgumentNullException("item"); - - if (!propName.HasValidStringValue()) - throw new DtoPropertyMapException("Property name (or key) is empty"); - - if (!dict.ContainsKey(propName)) - { - Add(item.PropertyName, item); - } - else - { - dict[propName] = item; - } - } - - /// - /// Adds or updates new items in the dictionary - /// - /// The key value pair collection to handle - public void AddOrUpdateRange(IEnumerable coll) - { - foreach (DtoPropertyAttributeMapping item in coll) - { - AddOrUpdate(item); - } - } - - /// - /// Gets an item by property name - /// - /// The name of the property to look for - /// The item if found null otherwise - public DtoPropertyAttributeMapping GetByPropertyName(string name) - { - return GetByPropertyName(name, StringComparison.InvariantCultureIgnoreCase); - } - - /// - /// Gets an item by property name - /// - /// The name of the property to look for - /// The string type - /// The item if found null otherwise - public DtoPropertyAttributeMapping GetByPropertyName(string name, StringComparison comparisonType) - { - IEnumerable q = from x in dict.Values - where x.PropertyName.Equals(name, comparisonType) - select x; - - if (q.Any()) - return q.Single(); - - return null; - } - - /// - /// Gets an item by attribute name - /// - /// The name of the property to look for - /// The item if found null otherwise - public DtoPropertyAttributeMapping GetByAttributeName(string name) - { - return GetByAttributeName(name, StringComparison.InvariantCultureIgnoreCase); - } - - /// - /// Gets an item by attribute name - /// - /// The name of the property to look for - /// The string type - /// The item if found null otherwise - public DtoPropertyAttributeMapping GetByAttributeName(string name, StringComparison comparisonType) - { - IEnumerable q = from x in dict.Values - where x.AttributeName.Equals(name, comparisonType) - select x; - - if (q.Any()) - return q.Single(); - - return null; - } } } \ No newline at end of file