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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 106 - (hide annotations) (download)
Sun Mar 10 12:25:54 2013 UTC (7 years, 7 months ago) by william
File size: 4015 byte(s)

1 william 92 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6    
7     namespace libxmltv.Core
8     {
9 william 97 public class PropertyList : PropertyList<string, object>, IPropertyList
10 william 92 {
11 william 97 public PropertyList() :base() { }
12 william 105 public PropertyList(IEnumerable<IPropertyValuePair<string, object>> collection) : base(collection) { }
13 william 97 public PropertyList(int capacity) : base(capacity) { }
14     }
15     public class PropertyList<TKey, TValue> : IPropertyList<TKey, TValue>
16     {
17 william 105 private PropertyCollection<IPropertyValuePair<TKey, TValue>> properties;
18     public PropertyList() { properties = new PropertyCollection<IPropertyValuePair<TKey, TValue>>(); }
19     public PropertyList(IEnumerable<IPropertyValuePair<TKey, TValue>> collection) : this() { foreach (var p in collection) { properties.AddProperty(p); } }
20 william 98 public PropertyList(int capacity)
21     {
22 william 105 properties = new PropertyCollection<IPropertyValuePair<TKey, TValue>>();
23 william 98 }
24 william 105 public IPropertyValuePair<TKey, TValue> this[int index] { get { return properties.ToList()[index]; } set { properties.ToList()[index] = value; } }
25     public IEnumerable<IPropertyValuePair<TKey, TValue>> this[TKey name]
26 william 100 {
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 william 105 public int IndexOfProperty(IPropertyValuePair<TKey, TValue> item) { return properties.ToList().IndexOf(item); }
38     public void InsertPropertyAtIndex(int index, IPropertyValuePair<TKey, TValue> item) { properties.ToList().Insert(index, item); }
39 william 98 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 william 106 IPropertyCollection<IPropertyValuePair<TKey, TValue>> collection = (properties as IPropertyCollection<IPropertyValuePair<TKey, TValue>>);
46 william 98 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 william 105 public void AddProperty(IPropertyValuePair<TKey, TValue> item) { properties.AddProperty(item); }
54 william 98 public void ClearProperties() { properties.ClearProperties(); }
55 william 105 public bool ContainsProperty(IPropertyValuePair<TKey, TValue> item) { return properties.Contains(item); }
56     public void CopyPropertiesTo(IPropertyValuePair<TKey, TValue>[] array, int arrayIndex) { properties.CopyPropertiesTo(array, arrayIndex); }
57     public bool RemoveProperty(IPropertyValuePair<TKey, TValue> item) { return properties.RemoveProperty(item); }
58     public IEnumerator<IPropertyValuePair<TKey, TValue>> GetEnumerator() { return properties.GetEnumerator(); }
59 william 95 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
60 william 97
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 william 106
66     public override string ToString()
67     {
68     return string.Format("Property Count: {0}", PropertyCount);
69     }
70 william 92 }
71     }

  ViewVC Help
Powered by ViewVC 1.1.22