Esempio n. 1
0
        public static double ToDouble(this BulkString @string)
        {
            if (@string.ToDoubleOrNull() is {} result)
            {
                return(result);
            }

            throw new ArgumentException("Bulk string is null", nameof(@string));
        }
Esempio n. 2
0
        public static byte[] ToBytes(this BulkString @string)
        {
            if (@string.IsNull)
            {
                return(null);
            }

            using var stream = new MemoryStream();
            @string.WriteContent(stream);
            return(stream.ToArray());
        }
Esempio n. 3
0
        public static double?ToDoubleOrNull(this BulkString @string)
        {
            if (@string.IsNull)
            {
                return(null);
            }

            if (ReferenceEquals(@string, Bounds.PositiveInfinity))
            {
                return(double.PositiveInfinity);
            }

            if (ReferenceEquals(@string, Bounds.NegativeInfinity))
            {
                return(double.NegativeInfinity);
            }

            using var stream = new MemoryStream();
            @string.WriteContent(stream);
            var doubleString = Encoding.UTF8.GetString(
                stream.GetBuffer(),
                0,
                checked ((int)stream.Length)
                );

            // todo move to constants
            if (doubleString == "+inf")
            {
                return(double.PositiveInfinity);
            }
            if (doubleString == "-inf")
            {
                return(double.NegativeInfinity);
            }

            return(double.Parse(doubleString, NumberStyles.Float, CultureInfo.InvariantCulture));
        }
Esempio n. 4
0
 public BulkString(Protocol.BulkString content)
 {
     this.content = content;
 }