comparison Pml/Elements/Collection.cs @ 103:8fe322656807

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