public void Serialize_NullStreamArgument_ThrowsArgumentException()
    {
        Map map = new Map();

        Assert.Throws <ArgumentNullException>(
            () => _serializer.Serialize(null, map));
    }
 public static void Serialize <T>(string filePath, T value, IStreamSerializer <T> streamSerializer, bool overwrite = true)
 {
     using (var fileStream = FileStreamHelper.NewWrite(filePath, overwrite))
     {
         streamSerializer.Serialize(fileStream, value);
     }
 }
Exemple #3
0
 public static byte[] GetSerializedBytes(this IStreamSerializer serializer, object obj)
 {
     using (var stream = new MemoryStream())
     {
         serializer.Serialize(obj, stream);
         return(stream.ToArray());
     }
 }
        private MemoryStream GetStream(TValue value)
        {
            var stream = new MemoryStream();

            _valueSerializer.Serialize(stream, value);
            stream.Position = 0;
            return(stream);
        }
Exemple #5
0
        /// <summary>
        /// Serializes to string.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serializer">The serializer.</param>
        /// <param name="obj">The object.</param>
        /// <param name="encoding">The encoding.</param>
        /// <returns>System.String.</returns>
        public static string SerializeToString <T>(this IStreamSerializer serializer, T obj, Encoding encoding = null)
        {
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(obj, stream);
                stream.Position = 0;
                var bytes = new byte[stream.Length];
                stream.Read(bytes, 0, (int)stream.Length);

                return(encoding == null?Convert.ToBase64String(bytes) : encoding.GetString(bytes, 0, bytes.Length));
            }
        }
Exemple #6
0
        public static bool CanSerializeStream <T>(this IStreamSerializer serializer, T item)
        {
            var encoder = Encoding.UTF8;

            using (var stream = new StreamReader(new MemoryStream(), encoder))
            {
                serializer.Serialize <T>(item, stream.BaseStream);
                stream.BaseStream.Position = 0;
                var obj = serializer.Deserialize <T>(stream.BaseStream);
                return(obj.Equals(item));
            }
        }
Exemple #7
0
        public static string SerializeToString <T>(this IStreamSerializer serializer, T obj, Encoding encoding = null)
        {
            var encoder = encoding ?? Encoding.UTF8;

            using (var stream = new MemoryStream())
            {
                serializer.Serialize <T>(obj, stream);
                stream.Position = 0;
                var bytes = new byte[stream.Length];
                stream.Read(bytes, 0, (int)stream.Length);

                return(Convert.ToBase64String(bytes));
            }
        }
Exemple #8
0
        public void SaveAsSimpleFont(Stream stream)
        {
            if (stream == null)
            {
                throw new PdfArgumentNullException("stream");
            }
            if (!stream.CanWrite)
            {
                throw new PdfArgumentException("stream");
            }
            CT_SimpleFont font = new CT_SimpleFont {
                Name = this.GetPostScriptName()
            };
            PdfRectangle fontBoundingBox = this.GetFontBoundingBox();

            font.BBox0       = fontBoundingBox.LowerLeftX;
            font.BBox1       = fontBoundingBox.LowerLeftY;
            font.BBox2       = fontBoundingBox.UpperRightX;
            font.BBox3       = fontBoundingBox.UpperRightY;
            font.Flags       = (int)this.GetFlag();
            font.ItalicAngle = this.GetItalicAngle();
            font.Ascent      = this.GetAscent();
            font.Descent     = this.GetDescent();
            font.CapHeight   = this.GetCapitalLetterHeight();
            font.StemV       = this.GetVerticalStem();
            List <CT_Width> list = new List <CT_Width>();

            foreach (KeyValuePair <int, int> pair in this.CMap.CurrentMap)
            {
                CT_Width width;
                width = new CT_Width {
                    Index = pair.Key,
                    Value = this.GetWidth(pair.Value)
                };
                list.Add(width);
            }
            font.Widths = list.ToArray();
            IStreamSerializer serializerByType = SerializerBuilder.GetSerializerByType(typeof(CT_SimpleFont));
            MemoryStream      stream2          = new MemoryStream();

            serializerByType.Serialize(stream2, font);
            stream2.Seek(0L, SeekOrigin.Begin);
            PdfFilter.FlateFilter.Encode(stream2, stream, null);
        }