/[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 105 by william, Sun Mar 10 11:35:26 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          public void AddProperty(PropertyValuePair<TKey, TValue> item) { AddProperty(item.Name, item.Value); }          {
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(IPropertyValuePair<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(IPropertyValuePair<TKey, TValue> item) { return ContainsProperty(item.Name); }
147          public void CopyPropertiesTo(PropertyValuePair<TKey, TValue>[] array, int arrayIndex)          public void CopyPropertiesTo(IPropertyValuePair<TKey, TValue>[] array, int arrayIndex)
148          {          {
149              var list = properties.ToList().Cast<PropertyValuePair<TKey, TValue>>().ToList();              var list = properties.ToList().Cast<IPropertyValuePair<TKey, TValue>>().ToList();
150              list.CopyTo(array, arrayIndex);              list.CopyTo(array, arrayIndex);
151          }          }
152          public bool RemoveProperty(PropertyValuePair<TKey, TValue> item) { return RemoveProperty(item.Name); }          public bool RemoveProperty(IPropertyValuePair<TKey, TValue> item) { return RemoveProperty(item.Name); }
153          IEnumerator<PropertyValuePair<TKey, TValue>> IEnumerable<PropertyValuePair<TKey, TValue>>.GetEnumerator() { return new PropertyDictionaryEnumerator(this, 2); }          IEnumerator<IPropertyValuePair<TKey, TValue>> IEnumerable<IPropertyValuePair<TKey, TValue>>.GetEnumerator() { return new PropertyDictionaryEnumerator(this, 2); }
154          System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return properties.GetEnumerator(); }          System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return properties.GetEnumerator(); }
155    
156          #region enumerator support          #region enumerator support
157          public class PropertyDictionaryEnumerator: IEnumerator<PropertyValuePair<TKey,TValue>>, IDisposable          public class PropertyDictionaryEnumerator : IEnumerator<IPropertyValuePair<TKey, TValue>>, IDisposable
158          {          {
159              private PropertyDictionary<TKey, TValue> dictionary;              private PropertyDictionary<TKey, TValue> dictionary;
160              private int index;              private int index;
161              private PropertyValuePair<TKey, TValue> current;              private IPropertyValuePair<TKey, TValue> current;
162              private int getEnumeratorRetType;              private int getEnumeratorRetType;
163              internal const int DictEntry = 1;              internal const int DictEntry = 1;
164              internal const int KeyValuePair = 2;              internal const int KeyValuePair = 2;
# Line 148  namespace libxmltv.Core Line 172  namespace libxmltv.Core
172                  this.current = new PropertyValuePair<TKey, TValue>();                  this.current = new PropertyValuePair<TKey, TValue>();
173              }              }
174    
175              public PropertyValuePair<TKey, TValue> Current              public IPropertyValuePair<TKey, TValue> Current
176              {              {
177                  get { return this.current; }                  get { return this.current; }
178              }              }
# Line 183  namespace libxmltv.Core Line 207  namespace libxmltv.Core
207                  {                  {
208                      if (this.dictionary.entries[this.index].hashCode >= 0)                      if (this.dictionary.entries[this.index].hashCode >= 0)
209                      {                      {
210                          this.current = new KeyValuePair<TKey, TValue>(this.dictionary.entries[this.index].name, this.dictionary.entries[this.index].value);                          this.current =(IPropertyValuePair<TKey,TValue>)(PropertyValuePair<TKey,TValue>)new KeyValuePair<TKey, TValue>(this.dictionary.entries[this.index].name, this.dictionary.entries[this.index].value);
211                          this.index++;                          this.index++;
212                          return true;                          return true;
213                      }                      }
# Line 200  namespace libxmltv.Core Line 224  namespace libxmltv.Core
224                      ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);                      ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
225                  }                  }
226                  this.index = 0;                  this.index = 0;
227                  this.current = new KeyValuePair<TKey, TValue>();                  this.current = (IPropertyValuePair<TKey, TValue>)(PropertyValuePair<TKey, TValue>)new KeyValuePair<TKey, TValue>();
228              }              }
229          }          }
230          #endregion            #endregion  

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

  ViewVC Help
Powered by ViewVC 1.1.22