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

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

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

--- trunk/libxmltv/Core/PropertyList.cs	2013/03/10 08:21:30	92
+++ trunk/libxmltv/Core/PropertyList.cs	2013/03/10 17:41:52	118
@@ -6,91 +6,68 @@
 
 namespace libxmltv.Core
 {
-    public class PropertyList : PropertyList<string, object>, IPropertyList { }
-    public class PropertyList<TKey, TValue> : IPropertyList<PropertyValuePair<TKey, TValue>>
+    [Serializable]
+    internal class PropertyList : PropertyList<string, object>, IPropertyList 
     {
-        private List<List<PropertyValuePair<TKey, TValue>>> properties;
-
-        public PropertyList() { properties = new List<List<PropertyValuePair<TKey, TValue>>>(); }
-        public PropertyList(IEnumerable<List<PropertyValuePair<TKey, TValue>>> collection) { properties = new List<List<PropertyValuePair<TKey, TValue>>>(collection); }
-        public PropertyList(int capacity) { properties = new List<List<PropertyValuePair<TKey, TValue>>>(); }
-
-
-        public PropertyValuePair<TKey, TValue> this[int index]
+        public PropertyList() :base() { }
+        public PropertyList(IEnumerable<IPropertyValuePair<string, object>> collection) : base(collection) { }
+        public PropertyList(int capacity) : base(capacity) { }
+    }
+    [Serializable]
+    internal class PropertyList<TKey, TValue> : IPropertyList<TKey, TValue>
+    {
+        private PropertyCollection<IPropertyValuePair<TKey, TValue>> properties;
+        public PropertyList() { properties = new PropertyCollection<IPropertyValuePair<TKey, TValue>>(); }
+        public PropertyList(IEnumerable<IPropertyValuePair<TKey, TValue>> collection) : this() { foreach (var p in collection) { properties.AddProperty(p); } }
+        public PropertyList(int capacity)
+        {
+            properties = new PropertyCollection<IPropertyValuePair<TKey, TValue>>();
+        }
+        public IPropertyValuePair<TKey, TValue> this[int index] { get { return properties.ToList()[index]; } set { properties.ToList()[index] = value; } }
+        public IEnumerable<IPropertyValuePair<TKey, TValue>> this[TKey name] 
         {
             get
             {
-                throw new NotImplementedException();
-            }
-            set
-            {
-                throw new NotImplementedException();
+                var list = properties.ToList().FindAll(s => s.Name.Equals(name));
+                if (list == null)
+                {
+                    throw new NullReferenceException(string.Format("Could not find any properties named '{0}'", name));
+                }
+                return list;
             }
         }
-
-        public int IndexOfProperty(PropertyValuePair<TKey, TValue> item)
-        {
-            throw new NotImplementedException();
-        }
-
-        public void InsertPropertyAtIndex(int index, PropertyValuePair<TKey, TValue> item)
-        {
-            throw new NotImplementedException();
-        }
-
-        public void RemovePropertyAt(int index)
-        {
-            throw new NotImplementedException();
-        }
-
-        public int PropertyCount
-        {
-            get { throw new NotImplementedException(); }
-        }
-
+        public int IndexOfProperty(IPropertyValuePair<TKey, TValue> item) { return properties.ToList().IndexOf(item); }
+        public void InsertPropertyAtIndex(int index, IPropertyValuePair<TKey, TValue> item) { properties.ToList().Insert(index, item); }
+        public void RemovePropertyAt(int index) { properties.RemoveProperty(this[index]); }
+        public int PropertyCount { get { return properties.PropertyCount; } }
         public bool IsReadOnly
         {
-            get { throw new NotImplementedException(); }
-        }
-
-        public void AddProperty(PropertyValuePair<TKey, TValue> item)
-        {
-            throw new NotImplementedException();
-        }
-
-        public void ClearProperties()
-        {
-            throw new NotImplementedException();
-        }
-
-        public bool ContainsProperty(PropertyValuePair<TKey, TValue> item)
-        {
-            throw new NotImplementedException();
-        }
-
-        public void CopyPropertiesTo(PropertyValuePair<TKey, TValue>[] array, int arrayIndex)
-        {
-            throw new NotImplementedException();
-        }
-
-        public bool RemoveProperty(PropertyValuePair<TKey, TValue> item)
-        {
-            throw new NotImplementedException();
-        }
-
-        public IEnumerator<PropertyValuePair<TKey, TValue>> GetEnumerator()
-        {
-            throw new NotImplementedException();
-        }
-
-        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
-        {
-            throw new NotImplementedException();
+            get
+            {
+                IPropertyCollection<IPropertyValuePair<TKey, TValue>> collection = (properties as IPropertyCollection<IPropertyValuePair<TKey, TValue>>);
+                if(collection == null)
+                {
+                    throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", properties.GetType().Name, typeof(IPropertyCollection<PropertyValuePair<TKey, TValue>>).Name));
+                }
+                return collection.IsReadOnly;
+            }
         }
+        public void AddProperty(IPropertyValuePair<TKey, TValue> item) { properties.AddProperty(item); }
+        public void ClearProperties() { properties.ClearProperties(); }
+        public bool ContainsProperty(IPropertyValuePair<TKey, TValue> item) { return properties.Contains(item); }
+        public void CopyPropertiesTo(IPropertyValuePair<TKey, TValue>[] array, int arrayIndex) { properties.CopyPropertiesTo(array, arrayIndex); }
+        public bool RemoveProperty(IPropertyValuePair<TKey, TValue> item) { return properties.RemoveProperty(item); }
+        public IEnumerator<IPropertyValuePair<TKey, TValue>> GetEnumerator() { return properties.GetEnumerator(); }
+        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
+
+
+        public bool ContainsProperty(TKey name, TValue value) { return ContainsProperty(new PropertyValuePair<TKey, TValue>(name, value)); }
+        public void AddProperty(TKey name, TValue value) { AddProperty(new PropertyValuePair<TKey, TValue>(name, value)); }
+        public void RemoveProperty(TKey name, TValue value) { RemoveProperty(new PropertyValuePair<TKey, TValue>(name, value)); }
 
-        IEnumerator<List<PropertyValuePair<TKey, TValue>>> IEnumerable<List<PropertyValuePair<TKey, TValue>>>.GetEnumerator()
+        public override string ToString()
         {
-            throw new NotImplementedException();
+            return string.Format("Property Count: {0}", PropertyCount);
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22