using System; using System.Collections.Generic; using System.Linq; using System.Text; using libxmltv.Interfaces; namespace libxmltv.Core { public class PropertyList : PropertyList, IPropertyList { public PropertyList() :base() { } public PropertyList(IEnumerable> collection) : base(collection) { } public PropertyList(int capacity) : base(capacity) { } } public class PropertyList : IPropertyList { private PropertyCollection> properties; public PropertyList() { properties = new PropertyCollection>(); } public PropertyList(IEnumerable> collection) : this() { foreach (var p in collection) { properties.AddProperty(p); } } public PropertyList(int capacity) { properties = new PropertyCollection>(); } public IPropertyValuePair this[int index] { get { return properties.ToList()[index]; } set { properties.ToList()[index] = value; } } public IEnumerable> this[TKey name] { get { var list = properties.ToList().FindAll(s => s.Name.Equals(name)); if (list == null) { throw new NullReferenceException(string.Format("Could not find any properties named '{0}'", name)); } return list; } } public int IndexOfProperty(IPropertyValuePair item) { return properties.ToList().IndexOf(item); } public void InsertPropertyAtIndex(int index, IPropertyValuePair item) { properties.ToList().Insert(index, item); } public void RemovePropertyAt(int index) { properties.RemoveProperty(this[index]); } public int PropertyCount { get { return properties.PropertyCount; } } public bool IsReadOnly { get { IPropertyCollection> collection = (properties as IPropertyCollection>); if(collection == null) { throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", properties.GetType().Name, typeof(IPropertyCollection>).Name)); } return collection.IsReadOnly; } } public void AddProperty(IPropertyValuePair item) { properties.AddProperty(item); } public void ClearProperties() { properties.ClearProperties(); } public bool ContainsProperty(IPropertyValuePair item) { return properties.Contains(item); } public void CopyPropertiesTo(IPropertyValuePair[] array, int arrayIndex) { properties.CopyPropertiesTo(array, arrayIndex); } public bool RemoveProperty(IPropertyValuePair item) { return properties.RemoveProperty(item); } public IEnumerator> GetEnumerator() { return properties.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public bool ContainsProperty(TKey name, TValue value) { return ContainsProperty(new PropertyValuePair(name, value)); } public void AddProperty(TKey name, TValue value) { AddProperty(new PropertyValuePair(name, value)); } public void RemoveProperty(TKey name, TValue value) { RemoveProperty(new PropertyValuePair(name, value)); } public override string ToString() { return string.Format("Property Count: {0}", PropertyCount); } } }