Exemplo n.º 1
0
            public bool ToBoolean()
            {
                switch (type)
                {
                case JsonValueType.Bool: return(boolValue);

                case JsonValueType.Integer: return(integerValue != 0);

                case JsonValueType.Real: return(NumberHelpers.Approximately(0, realValue));

                case JsonValueType.String: return(Convert.ToBoolean(ToString()));
                }
                return(default);
        /// <summary>
        /// Convert the value to a boolean.
        /// </summary>
        /// <param name="provider">Ignored.</param>
        /// <returns>Converted boolean value.</returns>
        public bool ToBoolean(IFormatProvider provider = null)
        {
            switch (type)
            {
            case TypeCode.Boolean:
                return(m_BoolValue);

            case TypeCode.Char:
                return(m_CharValue != default);

            case TypeCode.Byte:
                return(m_ByteValue != default);

            case TypeCode.SByte:
                return(m_SByteValue != default);

            case TypeCode.Int16:
                return(m_ShortValue != default);

            case TypeCode.UInt16:
                return(m_UShortValue != default);

            case TypeCode.Int32:
                return(m_IntValue != default);

            case TypeCode.UInt32:
                return(m_UIntValue != default);

            case TypeCode.Int64:
                return(m_LongValue != default);

            case TypeCode.UInt64:
                return(m_ULongValue != default);

            case TypeCode.Single:
                return(!Mathf.Approximately(m_FloatValue, default));

            case TypeCode.Double:
                return(NumberHelpers.Approximately(m_DoubleValue, default));

            default:
                return(default);
            }
        }