Ejemplo n.º 1
0
        public bool ToBoolean()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.False)
            {
                return(false);
            }
            if (type == ValueHandleType.True)
            {
                return(true);
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToBoolean(_bufferReader.Buffer, _offset, _length));
            }
            if (type == ValueHandleType.Int8)
            {
                int value = GetInt8();
                if (value == 0)
                {
                    return(false);
                }
                if (value == 1)
                {
                    return(true);
                }
            }
            return(XmlConverter.ToBoolean(GetString()));
        }
Ejemplo n.º 2
0
        public Decimal ToDecimal()
        {
            ValueHandleType valueHandleType = this.type;

            switch (valueHandleType)
            {
            case ValueHandleType.Decimal:
                return(this.GetDecimal());

            case ValueHandleType.Zero:
                return(new Decimal(0));

            case ValueHandleType.One:
                return(new Decimal(1));

            default:
                if (valueHandleType >= ValueHandleType.Int8 && valueHandleType <= ValueHandleType.Int64)
                {
                    return(this.ToLong());
                }
                if (valueHandleType == ValueHandleType.UInt64)
                {
                    return(this.GetUInt64());
                }
                if (valueHandleType == ValueHandleType.UTF8)
                {
                    return(XmlConverter.ToDecimal(this.bufferReader.Buffer, this.offset, this.length));
                }

                return(XmlConverter.ToDecimal(this.GetString()));
            }
        }
Ejemplo n.º 3
0
        public ulong ToULong()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.Zero)
            {
                return(0);
            }
            if (type == ValueHandleType.One)
            {
                return(1);
            }
            if (type >= ValueHandleType.Int8 && type <= ValueHandleType.Int64)
            {
                long value = ToLong();
                if (value >= 0)
                {
                    return((ulong)value);
                }
            }
            if (type == ValueHandleType.UInt64)
            {
                return(GetUInt64());
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToUInt64(_bufferReader.Buffer, _offset, _length));
            }
            return(XmlConverter.ToUInt64(GetString()));
        }
Ejemplo n.º 4
0
        public ulong ToULong()
        {
            ValueHandleType valueHandleType = this.type;

            switch (valueHandleType)
            {
            case ValueHandleType.Zero:
                return(0UL);

            case ValueHandleType.One:
                return(1UL);

            default:
                if (valueHandleType >= ValueHandleType.Int8 && valueHandleType <= ValueHandleType.Int64)
                {
                    long num = this.ToLong();
                    if (num >= 0L)
                    {
                        return((ulong)num);
                    }
                }
                if (valueHandleType == ValueHandleType.UInt64)
                {
                    return(this.GetUInt64());
                }
                if (valueHandleType == ValueHandleType.UTF8)
                {
                    return(XmlConverter.ToUInt64(this.bufferReader.Buffer, this.offset, this.length));
                }

                return(XmlConverter.ToUInt64(this.GetString()));
            }
        }
Ejemplo n.º 5
0
        public decimal ToDecimal()
        {
            ValueHandleType type = this.type;

            switch (type)
            {
            case ValueHandleType.Decimal:
                return(this.GetDecimal());

            case ValueHandleType.Zero:
                return(0M);

            case ValueHandleType.One:
                return(1M);
            }
            if ((type >= ValueHandleType.Int8) && (type <= ValueHandleType.Int64))
            {
                return(this.ToLong());
            }
            if (type == ValueHandleType.UInt64)
            {
                return(this.GetUInt64());
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToDecimal(this.bufferReader.Buffer, this.offset, this.length));
            }
            return(XmlConverter.ToDecimal(this.GetString()));
        }
Ejemplo n.º 6
0
        public bool ToBoolean()
        {
            ValueHandleType type = this.type;

            switch (type)
            {
            case ValueHandleType.False:
                return(false);

            case ValueHandleType.True:
                return(true);

            case ValueHandleType.UTF8:
                return(XmlConverter.ToBoolean(this.bufferReader.Buffer, this.offset, this.length));
            }
            if (type == ValueHandleType.Int8)
            {
                switch (this.GetInt8())
                {
                case 0:
                    return(false);

                case 1:
                    return(true);
                }
            }
            return(XmlConverter.ToBoolean(this.GetString()));
        }
Ejemplo n.º 7
0
        public decimal ToDecimal()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.Decimal)
            {
                return(GetDecimal());
            }
            if (type == ValueHandleType.Zero)
            {
                return(0);
            }
            if (type == ValueHandleType.One)
            {
                return(1);
            }
            if (type >= ValueHandleType.Int8 && type <= ValueHandleType.Int64)
            {
                return(ToLong());
            }
            if (type == ValueHandleType.UInt64)
            {
                return(GetUInt64());
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToDecimal(_bufferReader.Buffer, _offset, _length));
            }
            return(XmlConverter.ToDecimal(GetString()));
        }
Ejemplo n.º 8
0
        public int ToInt()
        {
            ValueHandleType valueHandleType = this.type;

            if (valueHandleType == ValueHandleType.Zero)
            {
                return(0);
            }
            if (valueHandleType == ValueHandleType.One)
            {
                return(1);
            }
            if (valueHandleType == ValueHandleType.Int8)
            {
                return(this.GetInt8());
            }
            if (valueHandleType == ValueHandleType.Int16)
            {
                return(this.GetInt16());
            }
            if (valueHandleType == ValueHandleType.Int32)
            {
                return(this.GetInt32());
            }
            if (valueHandleType == ValueHandleType.Int64)
            {
                long int64 = this.GetInt64();
                if (int64 >= int.MinValue && int64 <= int.MaxValue)
                {
                    return((int)int64);
                }
            }
            if (valueHandleType == ValueHandleType.UInt64)
            {
                ulong uint64 = this.GetUInt64();
                if (uint64 <= int.MaxValue)
                {
                    return((int)uint64);
                }
            }
            if (valueHandleType == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToInt32(this.bufferReader.Buffer, this.offset, this.length));
            }

            return(XmlConverter.ToInt32(this.GetString()));
        }
Ejemplo n.º 9
0
        public int ToInt()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.Zero)
            {
                return(0);
            }
            if (type == ValueHandleType.One)
            {
                return(1);
            }
            if (type == ValueHandleType.Int8)
            {
                return(GetInt8());
            }
            if (type == ValueHandleType.Int16)
            {
                return(GetInt16());
            }
            if (type == ValueHandleType.Int32)
            {
                return(GetInt32());
            }
            if (type == ValueHandleType.Int64)
            {
                long value = GetInt64();
                if (value >= int.MinValue && value <= int.MaxValue)
                {
                    return((int)value);
                }
            }
            if (type == ValueHandleType.UInt64)
            {
                ulong value = GetUInt64();
                if (value <= int.MaxValue)
                {
                    return((int)value);
                }
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToInt32(_bufferReader.Buffer, _offset, _length));
            }
            return(XmlConverter.ToInt32(GetString()));
        }
        public long ToLong()
        {
            ValueHandleType type = this.type;

            if (type == ValueHandleType.Zero)
            {
                return(0);
            }
            if (type == ValueHandleType.One)
            {
                return(1);
            }
            if (type == ValueHandleType.Int8)
            {
                return(GetInt8());
            }
            if (type == ValueHandleType.Int16)
            {
                return(GetInt16());
            }
            if (type == ValueHandleType.Int32)
            {
                return(GetInt32());
            }
            if (type == ValueHandleType.Int64)
            {
                return(GetInt64());
            }
            if (type == ValueHandleType.UInt64)
            {
                ulong value = GetUInt64();
                if (value <= long.MaxValue)
                {
                    return((long)value);
                }
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToInt64(bufferReader.Buffer, offset, length));
            }
            return(XmlConverter.ToInt64(GetString()));
        }
Ejemplo n.º 11
0
        public float ToSingle()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.Single)
            {
                return(GetSingle());
            }
            if (type == ValueHandleType.Double)
            {
                double value = GetDouble();

                if ((value >= float.MinValue && value <= float.MaxValue) || !double.IsFinite(value))
                {
                    return((float)value);
                }
            }
            if (type == ValueHandleType.Zero)
            {
                return(0);
            }
            if (type == ValueHandleType.One)
            {
                return(1);
            }
            if (type == ValueHandleType.Int8)
            {
                return(GetInt8());
            }
            if (type == ValueHandleType.Int16)
            {
                return(GetInt16());
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToSingle(_bufferReader.Buffer, _offset, _length));
            }
            return(XmlConverter.ToSingle(GetString()));
        }
Ejemplo n.º 12
0
        public long ToLong()
        {
            ValueHandleType valueHandleType = this.type;

            if (valueHandleType == ValueHandleType.Zero)
            {
                return(0L);
            }
            if (valueHandleType == ValueHandleType.One)
            {
                return(1L);
            }
            if (valueHandleType == ValueHandleType.Int8)
            {
                return(this.GetInt8());
            }
            if (valueHandleType == ValueHandleType.Int16)
            {
                return(this.GetInt16());
            }
            if (valueHandleType == ValueHandleType.Int32)
            {
                return(this.GetInt32());
            }
            if (valueHandleType == ValueHandleType.Int64)
            {
                return(this.GetInt64());
            }
            if (valueHandleType == ValueHandleType.UInt64)
            {
                return((long)this.GetUInt64());
            }
            if (valueHandleType == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToInt64(this.bufferReader.Buffer, this.offset, this.length));
            }

            return(XmlConverter.ToInt64(this.GetString()));
        }
Ejemplo n.º 13
0
        public float ToSingle()
        {
            ValueHandleType valueHandleType = this.type;

            if (valueHandleType == ValueHandleType.Single)
            {
                return(this.GetSingle());
            }
            if (valueHandleType == ValueHandleType.Double)
            {
                double value = GetDouble();
                if ((value >= Single.MinValue && value <= Single.MaxValue) || double.IsInfinity(value) || double.IsNaN(value))
                {
                    return((Single)value);
                }
            }
            if (valueHandleType == ValueHandleType.Zero)
            {
                return(0.0f);
            }
            if (valueHandleType == ValueHandleType.One)
            {
                return(1f);
            }
            if (valueHandleType == ValueHandleType.Int8)
            {
                return(this.GetInt8());
            }
            if (valueHandleType == ValueHandleType.Int16)
            {
                return(this.GetInt16());
            }
            if (valueHandleType == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToSingle(this.bufferReader.Buffer, this.offset, this.length));
            }

            return(XmlConverter.ToSingle(this.GetString()));
        }
Ejemplo n.º 14
0
        public double ToDouble()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.Double)
            {
                return(GetDouble());
            }
            if (type == ValueHandleType.Single)
            {
                return(GetSingle());
            }
            if (type == ValueHandleType.Zero)
            {
                return(0);
            }
            if (type == ValueHandleType.One)
            {
                return(1);
            }
            if (type == ValueHandleType.Int8)
            {
                return(GetInt8());
            }
            if (type == ValueHandleType.Int16)
            {
                return(GetInt16());
            }
            if (type == ValueHandleType.Int32)
            {
                return(GetInt32());
            }
            if (type == ValueHandleType.UTF8)
            {
                return(XmlConverter.ToDouble(_bufferReader.Buffer, _offset, _length));
            }
            return(XmlConverter.ToDouble(GetString()));
        }
 public ValueHandle(XmlBufferReader bufferReader)
 {
     this.bufferReader = bufferReader;
     this.type         = ValueHandleType.Empty;
 }
Ejemplo n.º 16
0
 public void SetValue(ValueHandleType iType, int iOffset, int iLength)
 {
     this.type   = iType;
     this.offset = iOffset;
     this.length = iLength;
 }
Ejemplo n.º 17
0
 public void SetValue(ValueHandleType type, int offset, int length)
 {
     _type   = type;
     _offset = offset;
     _length = length;
 }
Ejemplo n.º 18
0
 public ValueHandle(XmlBufferReader bufferReader)
 {
     this.bufferReader = bufferReader;
     this.type = ValueHandleType.Empty;
 }
Ejemplo n.º 19
0
        public string GetString()
        {
            ValueHandleType valueHandleType = this.type;

            if (valueHandleType == ValueHandleType.UTF8)
            {
                return(this.GetCharsText());
            }

            switch (valueHandleType)
            {
            case ValueHandleType.Empty:
                return(string.Empty);

            case ValueHandleType.True:
                return("true");

            case ValueHandleType.False:
                return("false");

            case ValueHandleType.Zero:
                return("0");

            case ValueHandleType.One:
                return("1");

            case ValueHandleType.Int8:
            case ValueHandleType.Int16:
            case ValueHandleType.Int32:
                return(XmlConverter.ToString(this.ToInt()));

            case ValueHandleType.Int64:
                return(XmlConverter.ToString(this.GetInt64()));

            case ValueHandleType.UInt64:
                return(XmlConverter.ToString(this.GetUInt64()));

            case ValueHandleType.Single:
                return(XmlConverter.ToString(this.GetSingle()));

            case ValueHandleType.Double:
                return(XmlConverter.ToString(this.GetDouble()));

            case ValueHandleType.Decimal:
                return(XmlConverter.ToString(this.GetDecimal()));

            case ValueHandleType.DateTime:
                return(XmlConverter.ToString(this.ToDateTime()));

            case ValueHandleType.TimeSpan:
                return(XmlConverter.ToString(this.ToTimeSpan()));

            case ValueHandleType.Guid:
                return(XmlConverter.ToString(this.ToGuid()));

            case ValueHandleType.UniqueId:
                return(XmlConverter.ToString(this.ToUniqueId()));

            case ValueHandleType.UTF8:
                return(this.GetCharsText());

            case ValueHandleType.EscapedUTF8:
                return(this.GetEscapedCharsText());

            case ValueHandleType.Base64:
                throw new NotSupportedException();

            case ValueHandleType.List:
                throw new NotSupportedException();

            //return XmlConverter.ToString(this.ToList());
            case ValueHandleType.Char:
                return(this.GetCharText());

            case ValueHandleType.Unicode:
                return(this.GetUnicodeCharsText());

            case ValueHandleType.ConstString:
                return(ValueHandle.constStrings[this.offset]);

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 20
0
 public ValueHandle(XmlBufferReader bufferReader)
 {
     _bufferReader = bufferReader;
     _type = ValueHandleType.Empty;
 }
Ejemplo n.º 21
0
 public void SetValue(ValueHandleType type)
 {
     this.type = type;
 }
Ejemplo n.º 22
0
 public void SetValue(ValueHandleType type)
 {
     _type = type;
 }
Ejemplo n.º 23
0
        public string GetString()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.UTF8)
            {
                return(GetCharsText());
            }

            switch (type)
            {
            case ValueHandleType.False:
                return("false");

            case ValueHandleType.True:
                return("true");

            case ValueHandleType.Zero:
                return("0");

            case ValueHandleType.One:
                return("1");

            case ValueHandleType.Int8:
            case ValueHandleType.Int16:
            case ValueHandleType.Int32:
                return(XmlConverter.ToString(ToInt()));

            case ValueHandleType.Int64:
                return(XmlConverter.ToString(GetInt64()));

            case ValueHandleType.UInt64:
                return(XmlConverter.ToString(GetUInt64()));

            case ValueHandleType.Single:
                return(XmlConverter.ToString(GetSingle()));

            case ValueHandleType.Double:
                return(XmlConverter.ToString(GetDouble()));

            case ValueHandleType.Decimal:
                return(XmlConverter.ToString(GetDecimal()));

            case ValueHandleType.DateTime:
                return(XmlConverter.ToString(ToDateTime()));

            case ValueHandleType.Empty:
                return(string.Empty);

            case ValueHandleType.Unicode:
                return(GetUnicodeCharsText());

            case ValueHandleType.EscapedUTF8:
                return(GetEscapedCharsText());

            case ValueHandleType.Char:
                return(GetCharText());

            case ValueHandleType.Dictionary:
                return(GetDictionaryString().Value);

            case ValueHandleType.Base64:
                byte[] bytes = ToByteArray();
                DiagnosticUtility.DebugAssert(bytes != null, "");
                return(Base64Encoding.GetString(bytes, 0, bytes.Length));

            case ValueHandleType.List:
                return(XmlConverter.ToString(ToList()));

            case ValueHandleType.UniqueId:
                return(XmlConverter.ToString(ToUniqueId()));

            case ValueHandleType.Guid:
                return(XmlConverter.ToString(ToGuid()));

            case ValueHandleType.TimeSpan:
                return(XmlConverter.ToString(ToTimeSpan()));

            case ValueHandleType.QName:
                return(GetQNameDictionaryText());

            case ValueHandleType.ConstString:
                return(s_constStrings[_offset]);

            default:
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
            }
        }
 public void SetValue(ValueHandleType type, int offset, int length)
 {
     this.type   = type;
     this.offset = offset;
     this.length = length;
 }
 public void SetValue(ValueHandleType type)
 {
     this.type = type;
 }
Ejemplo n.º 26
0
 public void SetValue(ValueHandleType iType, int iOffset, int iLength)
 {
     this.type = iType;
     this.offset = iOffset;
     this.length = iLength;
 }
Ejemplo n.º 27
0
 public ValueHandle(XmlBufferReader bufferReader)
 {
     _bufferReader = bufferReader;
     _type         = ValueHandleType.Empty;
 }
Ejemplo n.º 28
0
 void ReadValue(ValueHandle value, ValueHandleType type, int length)
 {
     int offset = ReadBytes(length);
     value.SetValue(type, offset, length);
 }
Ejemplo n.º 29
0
 public void SetValue(ValueHandleType type, int offset, int length)
 {
     _type = type;
     _offset = offset;
     _length = length;
 }
Ejemplo n.º 30
0
        private void ReadValue(ValueHandle value, ValueHandleType type, int length)
        {
            int offset = ReadBytes(length);

            value.SetValue(type, offset, length);
        }
Ejemplo n.º 31
0
 public void SetConstantValue(ValueHandleConstStringType constStringType)
 {
     type = ValueHandleType.ConstString;
     offset = (int)constStringType;
 }
Ejemplo n.º 32
0
 public void SetConstantValue(ValueHandleConstStringType constStringType)
 {
     _type   = ValueHandleType.ConstString;
     _offset = (int)constStringType;
 }
Ejemplo n.º 33
0
 public void SetValue(ValueHandleType type, int offset, int length)
 {
     this.type = type;
     this.offset = offset;
     this.length = length;
 }
Ejemplo n.º 34
0
 public void SetValue(ValueHandleType type)
 {
     _type = type;
 }
Ejemplo n.º 35
0
 private void ReadText(XmlTextNode textNode, ValueHandleType type, int length)
 {
     int offset = BufferReader.ReadBytes(length);
     textNode.Value.SetValue(type, offset, length);
     if (this.OutsideRootElement)
         VerifyWhitespace();
 }
Ejemplo n.º 36
0
        public string GetString()
        {
            ValueHandleType type = this.type;

            if (type == ValueHandleType.UTF8)
            {
                return(this.GetCharsText());
            }
            switch (type)
            {
            case ValueHandleType.Empty:
                return(string.Empty);

            case ValueHandleType.True:
                return("true");

            case ValueHandleType.False:
                return("false");

            case ValueHandleType.Zero:
                return("0");

            case ValueHandleType.One:
                return("1");

            case ValueHandleType.Int8:
            case ValueHandleType.Int16:
            case ValueHandleType.Int32:
                return(XmlConverter.ToString(this.ToInt()));

            case ValueHandleType.Int64:
                return(XmlConverter.ToString(this.GetInt64()));

            case ValueHandleType.UInt64:
                return(XmlConverter.ToString(this.GetUInt64()));

            case ValueHandleType.Single:
                return(XmlConverter.ToString(this.GetSingle()));

            case ValueHandleType.Double:
                return(XmlConverter.ToString(this.GetDouble()));

            case ValueHandleType.Decimal:
                return(XmlConverter.ToString(this.GetDecimal()));

            case ValueHandleType.DateTime:
                return(XmlConverter.ToString(this.ToDateTime()));

            case ValueHandleType.TimeSpan:
                return(XmlConverter.ToString(this.ToTimeSpan()));

            case ValueHandleType.Guid:
                return(XmlConverter.ToString(this.ToGuid()));

            case ValueHandleType.UniqueId:
                return(XmlConverter.ToString(this.ToUniqueId()));

            case ValueHandleType.UTF8:
                return(this.GetCharsText());

            case ValueHandleType.EscapedUTF8:
                return(this.GetEscapedCharsText());

            case ValueHandleType.Base64:
                return(Base64Encoding.GetString(this.ToByteArray()));

            case ValueHandleType.Dictionary:
                return(this.GetDictionaryString().Value);

            case ValueHandleType.List:
                return(XmlConverter.ToString(this.ToList()));

            case ValueHandleType.Char:
                return(this.GetCharText());

            case ValueHandleType.Unicode:
                return(this.GetUnicodeCharsText());

            case ValueHandleType.QName:
                return(this.GetQNameDictionaryText());

            case ValueHandleType.ConstString:
                return(constStrings[this.offset]);
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
        }