comparison Pml/Elements/Integer.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
3 namespace UCIS.Pml {
4 public class PmlInteger : PmlElement {
5 private UInt64 pUValue;
6 private Int64 pSValue;
7 private bool pSigned;
8
9 public PmlInteger() {
10 pSValue = 0;
11 pSigned = true;
12 }
13 public PmlInteger(UInt64 Value) {
14 pUValue = Value;
15 pSigned = false;
16 }
17 public PmlInteger(Int64 Value) {
18 pSValue = Value;
19 pSigned = true;
20 }
21 public PmlInteger(string Value) {
22 if (Int64.TryParse(Value, out pSValue)) {
23 pSigned = true;
24 } else if (UInt64.TryParse(Value, out pUValue)) {
25 pSigned = false;
26 } else {
27 throw new FormatException();
28 }
29 }
30
31 public Boolean IsSigned { get { return pSigned; } }
32
33 public override PmlType Type { get { return PmlType.Integer; } }
34
35 public override object ToObject() { return pSigned ? (Object)pSValue : (Object)pUValue; }
36 public override string ToString() { return pSigned ? pSValue.ToString() : pUValue.ToString(); }
37 public override bool ToBoolean() { return pSigned ? (pSValue != 0) : (pUValue != 0); }
38 public override byte ToByte() { return pSigned ? (Byte)pSValue : (Byte)pUValue; }
39 public override decimal ToDecimal() { return pSigned ? (Decimal)pSValue : (Decimal)pUValue; }
40 public override double ToDouble() { return pSigned ? (Double)pSValue : (Double)pUValue; }
41 public override short ToInt16() { return pSigned ? (Int16)pSValue : (Int16)pUValue; }
42 public override int ToInt32() { return pSigned ? (Int32)pSValue : (Int32)pUValue; }
43 public override long ToInt64() { return pSigned ? pSValue : (Int64)pUValue; }
44 public override sbyte ToSByte() { return pSigned ? (SByte)pSValue : (SByte)pUValue; }
45 public override float ToSingle() { return pSigned ? (Single)pSValue : (Single)pUValue; }
46 public override ushort ToUInt16() { return pSigned ? (UInt16)pSValue : (UInt16)pUValue; }
47 public override uint ToUInt32() { return pSigned ? (UInt32)pSValue : (UInt32)pUValue; }
48 public override ulong ToUInt64() { return pSigned ? (UInt64)pSValue : pUValue; }
49 public override char ToChar() { return pSigned ? (Char)pSValue : (Char)pUValue; }
50 public override byte[] ToByteArray() { return pSigned ? BitConverter.GetBytes(pSValue) : BitConverter.GetBytes(pUValue); }
51 }
52 }