/[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 09:01:33	95
+++ trunk/libxmltv/Core/PropertyDictionary.cs	2013/03/10 10:13:16	98
@@ -10,14 +10,27 @@
 
 namespace libxmltv.Core
 {
-    
+
     public class PropertyCollection<T> : IPropertyCollection<T>
     {
         private List<T> items = new List<T>();
         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); }
@@ -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 IPropertyCollection<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