Mercurial > hg > ucis.core
comparison Pml/Elements/Element.cs @ 0:3ab940a0c7a0
Initial commit
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 11 Sep 2012 16:28:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3ab940a0c7a0 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Text; | |
4 | |
5 namespace UCIS.Pml { | |
6 /*public enum PmlElementType : byte { | |
7 Null = 0, | |
8 | |
9 Dictionary = 1, | |
10 Collection = 2, | |
11 | |
12 Binary = 10, | |
13 String = 11, | |
14 | |
15 Integer = 20 | |
16 }*/ | |
17 public enum PmlType { | |
18 Null, | |
19 Dictionary, | |
20 Collection, | |
21 Binary, | |
22 String, | |
23 Integer, | |
24 //Number, | |
25 } | |
26 public abstract class PmlElement { | |
27 public abstract PmlType Type { get; } | |
28 | |
29 public virtual PmlElement GetChild(string name) { return null; } | |
30 public virtual PmlElement GetChild(int index) { return null; } | |
31 public virtual IEnumerable<PmlElement> GetChildren() { return null; } | |
32 public virtual IEnumerable<KeyValuePair<String, PmlElement>> GetNamedChildren() { return null; } | |
33 public virtual int GetChildCount() { return 0; } | |
34 public virtual void AddChild(string name, PmlElement value) { throw new NotSupportedException(); } | |
35 public virtual void AddChild(PmlElement value) { throw new NotSupportedException(); } | |
36 | |
37 public abstract object ToObject(); | |
38 public abstract override string ToString(); | |
39 public abstract bool ToBoolean(); | |
40 public abstract byte ToByte(); | |
41 public abstract decimal ToDecimal(); | |
42 public abstract double ToDouble(); | |
43 public abstract short ToInt16(); | |
44 public abstract int ToInt32(); | |
45 public abstract long ToInt64(); | |
46 public abstract sbyte ToSByte(); | |
47 public abstract float ToSingle(); | |
48 public abstract ushort ToUInt16(); | |
49 public abstract uint ToUInt32(); | |
50 public abstract ulong ToUInt64(); | |
51 public abstract char ToChar(); | |
52 public abstract byte[] ToByteArray(); | |
53 | |
54 public static explicit operator string(PmlElement e) { return e == null ? null : e.ToString(); } | |
55 public static explicit operator bool(PmlElement e) { return e == null ? false : e.ToBoolean(); } | |
56 public static explicit operator byte(PmlElement e) { return e == null ? (byte)0 : e.ToByte(); } | |
57 public static explicit operator decimal(PmlElement e) { return e == null ? (decimal)0 : e.ToDecimal(); } | |
58 public static explicit operator double(PmlElement e) { return e == null ? (double)0 : e.ToDouble(); } | |
59 public static explicit operator short(PmlElement e) { return e == null ? (short)0 : e.ToInt16(); } | |
60 public static explicit operator int(PmlElement e) { return e == null ? (int)0 : e.ToInt32(); } | |
61 public static explicit operator long(PmlElement e) { return e == null ? (long)0 : e.ToInt64(); } | |
62 public static explicit operator sbyte(PmlElement e) { return e == null ? (sbyte)0 : e.ToSByte(); } | |
63 public static explicit operator float(PmlElement e) { return e == null ? (float)0 : e.ToSingle(); } | |
64 public static explicit operator ushort(PmlElement e) { return e == null ? (ushort)0 : e.ToUInt16(); } | |
65 public static explicit operator uint(PmlElement e) { return e == null ? (uint)0 : e.ToUInt32(); } | |
66 public static explicit operator ulong(PmlElement e) { return e == null ? (ulong)0 : e.ToUInt64(); } | |
67 public static explicit operator char(PmlElement e) { return e == null ? '\0' : e.ToChar(); } | |
68 public static explicit operator byte[](PmlElement e) { return e == null ? null : e.ToByteArray(); } | |
69 | |
70 public static implicit operator PmlElement(String str) { return new PmlString(str); } | |
71 public static implicit operator PmlElement(UInt64 number) { return new PmlInteger(number); } | |
72 public static implicit operator PmlElement(UInt32 number) { return new PmlInteger(number); } | |
73 public static implicit operator PmlElement(Int64 number) { return new PmlInteger(number); } | |
74 public static implicit operator PmlElement(Int32 number) { return new PmlInteger(number); } | |
75 public static implicit operator PmlElement(Int16 number) { return new PmlInteger(number); } | |
76 public static implicit operator PmlElement(UInt16 number) { return new PmlInteger(number); } | |
77 public static implicit operator PmlElement(Byte number) { return new PmlInteger(number); } | |
78 //public static implicit operator PmlElement(Double number) { return new PmlNumber(number); } | |
79 } | |
80 } |