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 |
|
|
public PropertyList(IEnumerable<PropertyValuePair<string, object>> collection) : base(collection) { } |
13 |
|
|
public PropertyList(int capacity) : base(capacity) { } |
14 |
|
|
} |
15 |
|
|
public class PropertyList<TKey, TValue> : IPropertyList<TKey, TValue> |
16 |
|
|
{ |
17 |
william |
98 |
private PropertyCollection<PropertyValuePair<TKey, TValue>> properties; |
18 |
|
|
public PropertyList() { properties = new PropertyCollection<PropertyValuePair<TKey, TValue>>(); } |
19 |
|
|
public PropertyList(IEnumerable<PropertyValuePair<TKey, TValue>> collection) : this() { foreach (var p in collection) { properties.AddProperty(p); } } |
20 |
|
|
public PropertyList(int capacity) |
21 |
|
|
{ |
22 |
|
|
properties = new PropertyCollection<PropertyValuePair<TKey, TValue>>(); |
23 |
|
|
} |
24 |
|
|
public PropertyValuePair<TKey, TValue> this[int index] { get { return properties.ToList()[index]; } set { properties.ToList()[index] = value; } } |
25 |
william |
100 |
public IEnumerable<PropertyValuePair<TKey, TValue>> this[TKey name] |
26 |
|
|
{ |
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 |
|
|
//set |
37 |
|
|
//{ |
38 |
|
|
// var list = value; |
39 |
|
|
//} |
40 |
|
|
} |
41 |
william |
98 |
public int IndexOfProperty(PropertyValuePair<TKey, TValue> item) { return properties.ToList().IndexOf(item); } |
42 |
|
|
public void InsertPropertyAtIndex(int index, PropertyValuePair<TKey, TValue> item) { properties.ToList().Insert(index, item); } |
43 |
|
|
public void RemovePropertyAt(int index) { properties.RemoveProperty(this[index]); } |
44 |
|
|
public int PropertyCount { get { return properties.PropertyCount; } } |
45 |
|
|
public bool IsReadOnly |
46 |
|
|
{ |
47 |
|
|
get |
48 |
|
|
{ |
49 |
|
|
IPropertyCollection<PropertyValuePair<TKey, TValue>> collection = (properties as IPropertyCollection<PropertyValuePair<TKey, TValue>>); |
50 |
|
|
if(collection == null) |
51 |
|
|
{ |
52 |
|
|
throw new InvalidCastException(string.Format("Unable to cast: '{0}' to '{1}'", properties.GetType().Name, typeof(IPropertyCollection<PropertyValuePair<TKey, TValue>>).Name)); |
53 |
|
|
} |
54 |
|
|
return collection.IsReadOnly; |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
public void AddProperty(PropertyValuePair<TKey, TValue> item) { properties.AddProperty(item); } |
58 |
|
|
public void ClearProperties() { properties.ClearProperties(); } |
59 |
william |
95 |
public bool ContainsProperty(PropertyValuePair<TKey, TValue> item) { return properties.Contains(item); } |
60 |
william |
98 |
public void CopyPropertiesTo(PropertyValuePair<TKey, TValue>[] array, int arrayIndex) { properties.CopyPropertiesTo(array, arrayIndex); } |
61 |
|
|
public bool RemoveProperty(PropertyValuePair<TKey, TValue> item) { return properties.RemoveProperty(item); } |
62 |
william |
95 |
public IEnumerator<PropertyValuePair<TKey, TValue>> GetEnumerator() { return properties.GetEnumerator(); } |
63 |
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); } |
64 |
william |
97 |
|
65 |
|
|
|
66 |
|
|
public bool ContainsProperty(TKey name, TValue value) { return ContainsProperty(new PropertyValuePair<TKey, TValue>(name, value)); } |
67 |
|
|
public void AddProperty(TKey name, TValue value) { AddProperty(new PropertyValuePair<TKey, TValue>(name, value)); } |
68 |
|
|
public void RemoveProperty(TKey name, TValue value) { RemoveProperty(new PropertyValuePair<TKey, TValue>(name, value)); } |
69 |
william |
92 |
} |
70 |
|
|
} |