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); } |
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); } |