comparison Pml/Elements/Collection.cs @ 0:3ab940a0c7a0

Initial commit
author Ivo Smits <Ivo@UCIS.nl>
date Tue, 11 Sep 2012 16:28:53 +0200
parents
children 28dc7d535036
comparison
equal deleted inserted replaced
-1:000000000000 0:3ab940a0c7a0
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4
5 namespace UCIS.Pml {
6 public class PmlCollection : PmlElement, ICollection<PmlElement> {
7 private List<PmlElement> pItems = new List<PmlElement>();
8
9 public PmlCollection() { }
10 public PmlCollection(params PmlElement[] Elements) {
11 pItems.AddRange(Elements);
12 }
13 public PmlCollection(IEnumerable<PmlElement> Elements) {
14 pItems.AddRange(Elements);
15 }
16
17 public PmlElement Add(PmlElement Element) {
18 pItems.Add(Element);
19 return Element;
20 }
21 public void Remove(PmlElement Element) {
22 pItems.Remove(Element);
23 }
24 public void RemoveAt(int Index) {
25 pItems.RemoveAt(Index);
26 }
27 public void Clear() {
28 pItems.Clear();
29 }
30 public bool Contains(PmlElement item) {
31 return pItems.Contains(item);
32 }
33 public void CopyTo(PmlElement[] array, int arrayIndex) {
34 pItems.CopyTo(array, arrayIndex);
35 }
36 public int Count { get { return pItems.Count; } }
37 public bool IsReadOnly { get { return false; } }
38 public IEnumerator<PmlElement> GetEnumerator() { return pItems.GetEnumerator(); }
39 IEnumerator IEnumerable.GetEnumerator() { return pItems.GetEnumerator(); }
40 bool ICollection<PmlElement>.Remove(PmlElement item) { return pItems.Remove(item); }
41 void ICollection<PmlElement>.Add(PmlElement item) { Add(item); }
42
43 public override PmlType Type { get { return PmlType.Collection; } }
44
45 public override object ToObject() { return pItems; }
46 public override string ToString() { return null; }
47 public override bool ToBoolean() { return pItems.Count > 0; }
48 public override byte ToByte() { return (Byte)pItems.Count; }
49 public override decimal ToDecimal() { return pItems.Count; }
50 public override double ToDouble() { return pItems.Count; }
51 public override short ToInt16() { return (Int16)pItems.Count; }
52 public override int ToInt32() { return pItems.Count; }
53 public override long ToInt64() { return pItems.Count; }
54 public override sbyte ToSByte() { return (SByte)pItems.Count; }
55 public override float ToSingle() { return pItems.Count; }
56 public override ushort ToUInt16() { return (UInt16)pItems.Count; }
57 public override uint ToUInt32() { return (UInt32)pItems.Count; }
58 public override ulong ToUInt64() { return (UInt64)pItems.Count; }
59 public override char ToChar() { return '\0'; }
60 public override byte[] ToByteArray() { return null; }
61
62 //public override PmlElement GetChild(string name) { return GetChild(name); }
63 public override PmlElement GetChild(int index) { return pItems[index]; }
64 public override IEnumerable<PmlElement> GetChildren() { return pItems; }
65 public override IEnumerable<KeyValuePair<String, PmlElement>> GetNamedChildren() {
66 KeyValuePair<String, PmlElement>[] kvps = new KeyValuePair<string, PmlElement>[pItems.Count];
67 for (int i = 0; i < kvps.Length; i++) kvps[i] = new KeyValuePair<string,PmlElement>(null, pItems[i]);
68 return kvps;
69 }
70 public override int GetChildCount() { return pItems.Count; }
71 public override void AddChild(string name, PmlElement value) { Add(value); }
72 public override void AddChild(PmlElement value) { Add(value); }
73 }
74 }