/[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

revision 95 by william, Sun Mar 10 09:01:33 2013 UTC revision 102 by william, Sun Mar 10 11:08:58 2013 UTC
# Line 6  using libxmltv.Interfaces; Line 6  using libxmltv.Interfaces;
6    
7  namespace libxmltv.Core  namespace libxmltv.Core
8  {  {
9      public class PropertyList : PropertyList<string, object>, IPropertyList { }      public class PropertyList : PropertyList<string, object>, IPropertyList
     public class PropertyList<TKey, TValue> : IPropertyList<PropertyValuePair<TKey, TValue>>  
10      {      {
11          private List<PropertyValuePair<TKey, TValue>> properties;          public PropertyList() :base() { }
12          public PropertyList() { properties = new List<PropertyValuePair<TKey, TValue>>(); }          public PropertyList(IEnumerable<PropertyValuePair<string, object>> collection) : base(collection) { }
13          public PropertyList(IEnumerable<PropertyValuePair<TKey, TValue>> collection) { properties = new List<PropertyValuePair<TKey, TValue>>(collection); }          public PropertyList(int capacity) : base(capacity) { }
14          public PropertyList(int capacity) { properties = new List<PropertyValuePair<TKey, TValue>>(); }      }
15          public PropertyValuePair<TKey, TValue> this[int index] { get { return properties[index]; } set { properties[index] = value; } }      public class PropertyList<TKey, TValue> : IPropertyList<TKey, TValue>
16          public int IndexOfProperty(PropertyValuePair<TKey, TValue> item) { return properties.IndexOf(item); }      {
17          public void InsertPropertyAtIndex(int index, PropertyValuePair<TKey, TValue> item) { properties.Insert(index, item); }          private PropertyCollection<PropertyValuePair<TKey, TValue>> properties;
18          public void RemovePropertyAt(int index) { properties.RemoveAt(index); }          public PropertyList() { properties = new PropertyCollection<PropertyValuePair<TKey, TValue>>(); }
19          public int PropertyCount { get { return properties.Count; } }          public PropertyList(IEnumerable<PropertyValuePair<TKey, TValue>> collection) : this() { foreach (var p in collection) { properties.AddProperty(p); } }
20          public bool IsReadOnly { get { return (properties as IPropertyCollection<TKey>).IsReadOnly; } }          public PropertyList(int capacity)
21          public void AddProperty(PropertyValuePair<TKey, TValue> item) { properties.Add(item); }          {
22          public void ClearProperties() { properties.Clear(); }              properties = new PropertyCollection<PropertyValuePair<TKey, TValue>>();
23            }
24            public PropertyValuePair<TKey, TValue> this[int index] { get { return properties.ToList()[index]; } set { properties.ToList()[index] = value; } }
25            public IEnumerable<PropertyValuePair<TKey, TValue>> this[TKey name]
26            {
27                get
28                {
29                    var list = properties.ToList().FindAll(s => s.Name.Equals(name));
30                    if (list == null)
31                    {
32                        throw new NullReferenceException(string.Format("Could not find any properties named '{0}'", name));
33                    }
34                    return list;
35                }
36            }
37            public int IndexOfProperty(PropertyValuePair<TKey, TValue> item) { return properties.ToList().IndexOf(item); }
38            public void InsertPropertyAtIndex(int index, PropertyValuePair<TKey, TValue> item) { properties.ToList().Insert(index, item); }
39            public void RemovePropertyAt(int index) { properties.RemoveProperty(this[index]); }
40            public int PropertyCount { get { return properties.PropertyCount; } }
41            public bool IsReadOnly
42            {
43                get
44                {
45                    IPropertyCollection<PropertyValuePair<TKey, TValue>> collection = (properties as IPropertyCollection<PropertyValuePair<TKey, TValue>>);
46                    if(collection == null)
47                    {
48                        throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", properties.GetType().Name, typeof(IPropertyCollection<PropertyValuePair<TKey, TValue>>).Name));
49                    }
50                    return collection.IsReadOnly;
51                }
52            }
53            public void AddProperty(PropertyValuePair<TKey, TValue> item) { properties.AddProperty(item); }
54            public void ClearProperties() { properties.ClearProperties(); }
55          public bool ContainsProperty(PropertyValuePair<TKey, TValue> item) { return properties.Contains(item); }          public bool ContainsProperty(PropertyValuePair<TKey, TValue> item) { return properties.Contains(item); }
56          public void CopyPropertiesTo(PropertyValuePair<TKey, TValue>[] array, int arrayIndex) { properties.CopyTo(array, arrayIndex); }          public void CopyPropertiesTo(PropertyValuePair<TKey, TValue>[] array, int arrayIndex) { properties.CopyPropertiesTo(array, arrayIndex); }
57          public bool RemoveProperty(PropertyValuePair<TKey, TValue> item) { return properties.Remove(item); }          public bool RemoveProperty(PropertyValuePair<TKey, TValue> item) { return properties.RemoveProperty(item); }
58          public IEnumerator<PropertyValuePair<TKey, TValue>> GetEnumerator() { return properties.GetEnumerator(); }          public IEnumerator<PropertyValuePair<TKey, TValue>> GetEnumerator() { return properties.GetEnumerator(); }
59          System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); }          System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
60    
61    
62            public bool ContainsProperty(TKey name, TValue value) { return ContainsProperty(new PropertyValuePair<TKey, TValue>(name, value)); }
63            public void AddProperty(TKey name, TValue value) { AddProperty(new PropertyValuePair<TKey, TValue>(name, value)); }
64            public void RemoveProperty(TKey name, TValue value) { RemoveProperty(new PropertyValuePair<TKey, TValue>(name, value)); }
65      }      }
66  }  }

Legend:
Removed from v.95  
changed lines
  Added in v.102

  ViewVC Help
Powered by ViewVC 1.1.22