Exemplo n.º 1
0
        public void TextWithEncoding_ImplicitOperator_1()
        {
            TextWithEncoding text = "Hello";

            byte[] bytes = text.ToBytes();
            Assert.AreEqual(5, bytes.Length);
        }
Exemplo n.º 2
0
        public void TextWithEncoding_Construction_3()
        {
            TextWithEncoding text = new TextWithEncoding("Hello", true);

            byte[] bytes = text.ToBytes();
            Assert.AreEqual(5, bytes.Length);
        }
Exemplo n.º 3
0
        public void TextWithEncoding_Construction_4()
        {
            TextWithEncoding text = new TextWithEncoding("Привет", Encoding.GetEncoding(1251));

            byte[] bytes = text.ToBytes();
            Assert.AreEqual(6, bytes.Length);
        }
Exemplo n.º 4
0
        public void TextWithEncoding_Construction_2()
        {
            TextWithEncoding text = new TextWithEncoding("Привет");

            byte[] bytes = text.ToBytes();
            Assert.AreEqual(12, bytes.Length);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Записываем строку в произвольной кодировке.
        /// </summary>
        public static Stream EncodeTextWithEncoding
        (
            [NotNull] this Stream stream,
            [CanBeNull] TextWithEncoding text
        )
        {
            if (!ReferenceEquals(text, null))
            {
                byte[] bytes = text.ToBytes();

                stream.Write(bytes, 0, bytes.Length);
            }

            return(stream);
        }