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

Legend:
Removed from v.97  
changed lines
  Added in v.118

  ViewVC Help
Powered by ViewVC 1.1.22