string ValueAsString(BinXmlToken token) {
            try {
                CheckValueTokenBounds();
                switch ( token ) {
                    case BinXmlToken.SQL_NCHAR:
                    case BinXmlToken.SQL_NVARCHAR:
                    case BinXmlToken.SQL_NTEXT:
                        return GetString( this.tokDataPos, this.tokLen );

                    case BinXmlToken.XSD_BOOLEAN: {
                            if ( 0 == this.data[this.tokDataPos] )
                                return "false";
                            else
                                return "true";
                        }

                    case BinXmlToken.SQL_BIT:
                    case BinXmlToken.SQL_TINYINT:
                    case BinXmlToken.SQL_SMALLINT:
                    case BinXmlToken.SQL_INT:
                    case BinXmlToken.SQL_BIGINT:
                    case BinXmlToken.XSD_BYTE:
                    case BinXmlToken.XSD_UNSIGNEDSHORT:
                    case BinXmlToken.XSD_UNSIGNEDINT:
                        return ValueAsLong().ToString( CultureInfo.InvariantCulture );

                    case BinXmlToken.XSD_UNSIGNEDLONG:
                        return ValueAsULong().ToString( CultureInfo.InvariantCulture );

                    case BinXmlToken.SQL_REAL:
                        return XmlConvert.ToString( GetSingle( this.tokDataPos ) );

                    case BinXmlToken.SQL_FLOAT:
                        return XmlConvert.ToString( GetDouble( this.tokDataPos ) );

                    case BinXmlToken.SQL_UUID: {
                            int a; short b, c;
                            int pos = this.tokDataPos;
                            a = GetInt32( pos );
                            b = GetInt16( pos + 4 );
                            c = GetInt16( pos + 6 );
                            Guid v = new Guid( a, b, c, data[pos + 8], data[pos + 9], data[pos + 10], data[pos + 11], data[pos + 12], data[pos + 13], data[pos + 14], data[pos + 15] );
                            return v.ToString();
                        }

                    case BinXmlToken.SQL_SMALLMONEY: {
                            BinXmlSqlMoney v = new BinXmlSqlMoney( GetInt32( this.tokDataPos ) );
                            return v.ToString();
                        }
                    case BinXmlToken.SQL_MONEY: {
                            BinXmlSqlMoney v = new BinXmlSqlMoney( GetInt64( this.tokDataPos ) );
                            return v.ToString();
                        }

                    case BinXmlToken.XSD_DECIMAL:
                    case BinXmlToken.SQL_DECIMAL:
                    case BinXmlToken.SQL_NUMERIC: {
                            BinXmlSqlDecimal v = new BinXmlSqlDecimal( this.data, this.tokDataPos, token == BinXmlToken.XSD_DECIMAL );
                            return v.ToString();
                        }

                    case BinXmlToken.SQL_CHAR:
                    case BinXmlToken.SQL_VARCHAR:
                    case BinXmlToken.SQL_TEXT: {
                            int pos = this.tokDataPos;
                            int codepage = GetInt32( pos );
                            Encoding enc = System.Text.Encoding.GetEncoding( codepage );
                            return enc.GetString( this.data, pos + 4, this.tokLen - 4 );
                        }

                    case BinXmlToken.SQL_VARBINARY:
                    case BinXmlToken.SQL_BINARY:
                    case BinXmlToken.SQL_IMAGE:
                    case BinXmlToken.SQL_UDT:
                    case BinXmlToken.XSD_BASE64: {
                            return Convert.ToBase64String( this.data, this.tokDataPos, this.tokLen );
                        }

                    case BinXmlToken.XSD_BINHEX:
                        return BinHexEncoder.Encode( this.data, this.tokDataPos, this.tokLen );

                    case BinXmlToken.SQL_DATETIME:
                    case BinXmlToken.SQL_SMALLDATETIME:
                    case BinXmlToken.XSD_TIME:
                    case BinXmlToken.XSD_DATE:
                    case BinXmlToken.XSD_DATETIME:
                    case BinXmlToken.XSD_KATMAI_DATE:
                    case BinXmlToken.XSD_KATMAI_DATETIME:
                    case BinXmlToken.XSD_KATMAI_TIME:
                    case BinXmlToken.XSD_KATMAI_DATEOFFSET:
                    case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
                    case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
                        return ValueAsDateTimeString();

                    case BinXmlToken.XSD_QNAME: {
                            int nameNum = ParseMB32( this.tokDataPos );
                            if ( nameNum < 0 || nameNum >= this.symbolTables.qnameCount )
                                throw new XmlException( Res.XmlBin_InvalidQNameID, String.Empty );
                            QName qname = this.symbolTables.qnametable[nameNum];
                            if ( qname.prefix.Length == 0 )
                                return qname.localname;
                            else
                                return String.Concat( qname.prefix, ":", qname.localname );
                        }

                    default:
                        throw ThrowUnexpectedToken( this.token );
                }
            }
            catch {
                this.state = ScanState.Error;
                throw;
            }
        }
        private string ValueAsString(BinXmlToken token)
        {
            string str;
            try
            {
                int num8;
                this.CheckValueTokenBounds();
                switch (token)
                {
                    case BinXmlToken.SQL_SMALLINT:
                    case BinXmlToken.SQL_INT:
                    case BinXmlToken.SQL_BIT:
                    case BinXmlToken.SQL_TINYINT:
                    case BinXmlToken.SQL_BIGINT:
                    case BinXmlToken.XSD_BYTE:
                    case BinXmlToken.XSD_UNSIGNEDSHORT:
                    case BinXmlToken.XSD_UNSIGNEDINT:
                        return this.ValueAsLong().ToString(CultureInfo.InvariantCulture);

                    case BinXmlToken.SQL_REAL:
                        return XmlConvert.ToString(this.GetSingle(this.tokDataPos));

                    case BinXmlToken.SQL_FLOAT:
                        return XmlConvert.ToString(this.GetDouble(this.tokDataPos));

                    case BinXmlToken.SQL_MONEY:
                    {
                        BinXmlSqlMoney money2 = new BinXmlSqlMoney(this.GetInt64(this.tokDataPos));
                        return money2.ToString();
                    }
                    case BinXmlToken.SQL_UUID:
                    {
                        int tokDataPos = this.tokDataPos;
                        int a = this.GetInt32(tokDataPos);
                        short b = this.GetInt16(tokDataPos + 4);
                        short c = this.GetInt16(tokDataPos + 6);
                        Guid guid = new Guid(a, b, c, this.data[tokDataPos + 8], this.data[tokDataPos + 9], this.data[tokDataPos + 10], this.data[tokDataPos + 11], this.data[tokDataPos + 12], this.data[tokDataPos + 13], this.data[tokDataPos + 14], this.data[tokDataPos + 15]);
                        return guid.ToString();
                    }
                    case BinXmlToken.SQL_DECIMAL:
                    case BinXmlToken.SQL_NUMERIC:
                    case BinXmlToken.XSD_DECIMAL:
                    {
                        BinXmlSqlDecimal num5 = new BinXmlSqlDecimal(this.data, this.tokDataPos, token == BinXmlToken.XSD_DECIMAL);
                        return num5.ToString();
                    }
                    case BinXmlToken.SQL_BINARY:
                    case BinXmlToken.SQL_VARBINARY:
                    case BinXmlToken.SQL_IMAGE:
                    case BinXmlToken.SQL_UDT:
                    case BinXmlToken.XSD_BASE64:
                        return Convert.ToBase64String(this.data, this.tokDataPos, this.tokLen);

                    case BinXmlToken.SQL_CHAR:
                    case BinXmlToken.SQL_VARCHAR:
                    case BinXmlToken.SQL_TEXT:
                    {
                        int pos = this.tokDataPos;
                        return Encoding.GetEncoding(this.GetInt32(pos)).GetString(this.data, pos + 4, this.tokLen - 4);
                    }
                    case BinXmlToken.SQL_NCHAR:
                    case BinXmlToken.SQL_NVARCHAR:
                    case BinXmlToken.SQL_NTEXT:
                        return this.GetString(this.tokDataPos, this.tokLen);

                    case BinXmlToken.SQL_DATETIME:
                    case BinXmlToken.SQL_SMALLDATETIME:
                    case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
                    case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
                    case BinXmlToken.XSD_KATMAI_DATEOFFSET:
                    case BinXmlToken.XSD_KATMAI_TIME:
                    case BinXmlToken.XSD_KATMAI_DATETIME:
                    case BinXmlToken.XSD_KATMAI_DATE:
                    case BinXmlToken.XSD_TIME:
                    case BinXmlToken.XSD_DATETIME:
                    case BinXmlToken.XSD_DATE:
                        return this.ValueAsDateTimeString();

                    case BinXmlToken.SQL_SMALLMONEY:
                    {
                        BinXmlSqlMoney money = new BinXmlSqlMoney(this.GetInt32(this.tokDataPos));
                        return money.ToString();
                    }
                    case BinXmlToken.XSD_BINHEX:
                        return BinHexEncoder.Encode(this.data, this.tokDataPos, this.tokLen);

                    case BinXmlToken.XSD_BOOLEAN:
                        if (this.data[this.tokDataPos] != 0)
                        {
                            return "true";
                        }
                        return "false";

                    case BinXmlToken.XSD_UNSIGNEDLONG:
                        return this.ValueAsULong().ToString(CultureInfo.InvariantCulture);

                    case BinXmlToken.XSD_QNAME:
                        num8 = this.ParseMB32(this.tokDataPos);
                        if ((num8 < 0) || (num8 >= this.symbolTables.qnameCount))
                        {
                            throw new XmlException("XmlBin_InvalidQNameID", string.Empty);
                        }
                        break;

                    default:
                        throw this.ThrowUnexpectedToken(this.token);
                }
                QName name = this.symbolTables.qnametable[num8];
                if (name.prefix.Length == 0)
                {
                    return name.localname;
                }
                return (name.prefix + ":" + name.localname);
            }
            catch
            {
                this.state = ScanState.Error;
                throw;
            }
            return str;
        }