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

revision 95 by william, Sun Mar 10 09:01:33 2013 UTC revision 98 by william, Sun Mar 10 10:13:16 2013 UTC
# Line 10  using System.Reflection; Line 10  using System.Reflection;
10    
11  namespace libxmltv.Core  namespace libxmltv.Core
12  {  {
13        
14      public class PropertyCollection<T> : IPropertyCollection<T>      public class PropertyCollection<T> : IPropertyCollection<T>
15      {      {
16          private List<T> items = new List<T>();          private List<T> items = new List<T>();
17          public PropertyCollection() : this(new List<T>()) { }          public PropertyCollection() : this(new List<T>()) { }
18          public PropertyCollection(ICollection<T> collection) { foreach (var t in collection) { items.Add(t); } }          public PropertyCollection(ICollection<T> collection) { foreach (var t in collection) { items.Add(t); } }
19          public int PropertyCount { get { return items.Count; } }          public int PropertyCount { get { return items.Count; } }
20          public bool IsReadOnly { get { return (items as ICollection<T>).IsReadOnly; } }  
21            public bool IsReadOnly
22            {
23                get
24                {
25                    ICollection<T> collection = (items as ICollection<T>);
26                    if (collection == null)
27                    {
28                        throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", items.GetType().Name, typeof(ICollection<T>).Name));
29                    }
30                    return collection.IsReadOnly;
31                }
32            }
33    
34          public void AddProperty(T item) { items.Add(item); }          public void AddProperty(T item) { items.Add(item); }
35          public void ClearProperties() { items.Clear(); }          public void ClearProperties() { items.Clear(); }
36          public bool ContainsProperty(T item) { return items.Contains(item); }          public bool ContainsProperty(T item) { return items.Contains(item); }
# Line 116  namespace libxmltv.Core Line 129  namespace libxmltv.Core
129          public bool RemoveProperty(TKey key) { return properties.Remove(key); }          public bool RemoveProperty(TKey key) { return properties.Remove(key); }
130          public bool TryGetPropertyValue(TKey key, out TValue value) { return properties.TryGetValue(key, out value); }          public bool TryGetPropertyValue(TKey key, out TValue value) { return properties.TryGetValue(key, out value); }
131          public int PropertyCount { get { return properties.Count; } }          public int PropertyCount { get { return properties.Count; } }
132          public bool IsReadOnly { get { return (properties as IPropertyCollection<TKey>).IsReadOnly; } }          public bool IsReadOnly
133            {
134                get
135                {
136                    IDictionary<TKey, TValue> collection = (properties as IDictionary<TKey, TValue>);
137                    if (collection == null)
138                    {
139                        throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", properties.GetType().Name, typeof(IDictionary<TKey, TValue>).Name));
140                    }
141                    return collection.IsReadOnly;
142                }
143            }
144          public void AddProperty(PropertyValuePair<TKey, TValue> item) { AddProperty(item.Name, item.Value); }          public void AddProperty(PropertyValuePair<TKey, TValue> item) { AddProperty(item.Name, item.Value); }
145          public void ClearProperties() { properties.Clear(); }          public void ClearProperties() { properties.Clear(); }
146          public bool ContainsProperty(PropertyValuePair<TKey, TValue> item) { return ContainsProperty(item.Name); }          public bool ContainsProperty(PropertyValuePair<TKey, TValue> item) { return ContainsProperty(item.Name); }

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

  ViewVC Help
Powered by ViewVC 1.1.22