--- trunk/libxmltv/Core/PropertyDictionary.cs 2013/03/10 08:45:58 94 +++ trunk/libxmltv/Core/PropertyDictionary.cs 2013/03/10 10:13:16 98 @@ -17,7 +17,20 @@ public PropertyCollection() : this(new List()) { } public PropertyCollection(ICollection collection) { foreach (var t in collection) { items.Add(t); } } public int PropertyCount { get { return items.Count; } } - public bool IsReadOnly { get { return (items as ICollection).IsReadOnly; } } + + public bool IsReadOnly + { + get + { + ICollection collection = (items as ICollection); + if (collection == null) + { + throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", items.GetType().Name, typeof(ICollection).Name)); + } + return collection.IsReadOnly; + } + } + public void AddProperty(T item) { items.Add(item); } public void ClearProperties() { items.Clear(); } public bool ContainsProperty(T item) { return items.Contains(item); } @@ -26,7 +39,7 @@ public IEnumerator GetEnumerator() { return items.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return items.GetEnumerator(); } } - public class PropertyDictionary : PropertyDictionary + public class PropertyDictionary : PropertyDictionary, IPropertyDictionary { public PropertyDictionary() : base() { } public PropertyDictionary(IPropertyDictionary dictionary) : base(dictionary) { } @@ -116,7 +129,18 @@ public bool RemoveProperty(TKey key) { return properties.Remove(key); } public bool TryGetPropertyValue(TKey key, out TValue value) { return properties.TryGetValue(key, out value); } public int PropertyCount { get { return properties.Count; } } - public bool IsReadOnly { get { return (properties as ICollection).IsReadOnly; } } + public bool IsReadOnly + { + get + { + IDictionary collection = (properties as IDictionary); + if (collection == null) + { + throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", properties.GetType().Name, typeof(IDictionary).Name)); + } + return collection.IsReadOnly; + } + } public void AddProperty(PropertyValuePair item) { AddProperty(item.Name, item.Value); } public void ClearProperties() { properties.Clear(); } public bool ContainsProperty(PropertyValuePair item) { return ContainsProperty(item.Name); }