using System; using System.Collections.Generic; using System.Linq; using System.Text; using libxmltv.Interfaces; using System.Runtime.Serialization; namespace libxmltv.Core { public class PropertyCollection : IPropertyCollection { private List items = new List(); public PropertyCollection() : this(new List()) { } public PropertyCollection(ICollection collection) { foreach (var t in collection) { items.Add(t); } } public int PropertyCount { get { return items.Count; } } public bool IsReadOnly { get { return (items as ICollection).IsReadOnly; } } public void AddProperty(T item) { items.Add(item); } public void ClearProperties() { items.Clear(); } public bool ContainsProperty(T item) { return items.Contains(item); } public void CopyPropertiesTo(T[] array, int arrayIndex) { items.CopyTo(array, arrayIndex); } public bool RemoveProperty(T item) { return items.Remove(item); } public IEnumerator GetEnumerator() { return items.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return items.GetEnumerator(); } } public class PropertyDictionary : IPropertyDictionary { private Dictionary properties; public PropertyDictionary() { properties = new Dictionary(); } public PropertyDictionary(IPropertyDictionary dictionary) { properties = new Dictionary(); foreach (var d in dictionary) { properties.Add(d.Key, d.Value); } } public PropertyDictionary(IEqualityComparer comparer) { properties = new Dictionary(comparer); } public PropertyDictionary(int capacity) { properties = new Dictionary(capacity); } public PropertyDictionary(IPropertyDictionary dictionary, IEqualityComparer comparer) : this(comparer) { foreach (var d in dictionary) { properties.Add(d.Key, d.Value); } } public PropertyDictionary(int capacity, IEqualityComparer comparer) { properties = new Dictionary(capacity, comparer); } protected PropertyDictionary(SerializationInfo info, StreamingContext context) { } public IPropertyCollection PropertyKeys { get { return new PropertyCollection(properties.Keys); } } public IPropertyCollection PropertyValues { get { return new PropertyCollection(properties.Values); } } public TValue this[TKey key] { get { if (this.ContainsProperty(key)) { return properties[key]; } else { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", key)); } } set { if (this.ContainsProperty(key)) { properties[key] = value; } else { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", key)); } } } public void AddProperty(TKey key, TValue value) { if (properties.ContainsKey(key)) { this[key] = value; } else { properties.Add(key, value); } } public bool ContainsProperty(TKey key) { return properties.ContainsKey(key); } public bool RemoveProperty(TKey key) { return properties.Remove(key); } public bool TryGetPropertyValue(TKey key, out TValue value) { return properties.TryGetValue(key, out value); } public int PropertyCount { get { return properties.Count; } } public bool IsReadOnly { get { return (properties as ICollection).IsReadOnly; } } public void AddProperty(KeyValuePair item) { AddProperty(item.Key, item.Value); } public void ClearProperties() { properties.Clear(); } public bool ContainsProperty(KeyValuePair item) { return ContainsProperty(item.Key); } public void CopyPropertiesTo(KeyValuePair[] array, int arrayIndex) { var list = properties.ToList(); list.CopyTo(array, arrayIndex); } public bool RemoveProperty(KeyValuePair item) { return RemoveProperty(item.Key); } public IEnumerator> GetEnumerator() { return properties.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return properties.GetEnumerator(); } } public class PropertyDictionary : PropertyDictionary { } }