/[xmltv_parser]/trunk/libxmltv/Core/PropertyDictionary.cs
ViewVC logotype

Diff of /trunk/libxmltv/Core/PropertyDictionary.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- 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<T>()) { }
         public PropertyCollection(ICollection<T> collection) { foreach (var t in collection) { items.Add(t); } }
         public int PropertyCount { get { return items.Count; } }
-        public bool IsReadOnly { get { return (items as ICollection<T>).IsReadOnly; } }
+
+        public bool IsReadOnly
+        {
+            get
+            {
+                ICollection<T> collection = (items as ICollection<T>);
+                if (collection == null)
+                {
+                    throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", items.GetType().Name, typeof(ICollection<T>).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<T> GetEnumerator() { return items.GetEnumerator(); }
         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return items.GetEnumerator(); }
     }
-    public class PropertyDictionary : PropertyDictionary<string, object> 
+    public class PropertyDictionary : PropertyDictionary<string, object>, 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<TKey>).IsReadOnly; } }
+        public bool IsReadOnly
+        {
+            get
+            {
+                IDictionary<TKey, TValue> collection = (properties as IDictionary<TKey, TValue>);
+                if (collection == null)
+                {
+                    throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", properties.GetType().Name, typeof(IDictionary<TKey, TValue>).Name));
+                }
+                return collection.IsReadOnly;
+            }
+        }
         public void AddProperty(PropertyValuePair<TKey, TValue> item) { AddProperty(item.Name, item.Value); }
         public void ClearProperties() { properties.Clear(); }
         public bool ContainsProperty(PropertyValuePair<TKey, TValue> item) { return ContainsProperty(item.Name); }

 

  ViewVC Help
Powered by ViewVC 1.1.22