예제 #1
0
        /// <summary>
        /// Writes the specified obj.
        /// </summary>
        /// <typeparam name="T">Generic type</typeparam>
        /// <param name="obj">The obj.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="formatter">The formatter.</param>
        /// <param name="compress">if set to <c>true</c> [compress].</param>
        /// <exception cref="System.ArgumentNullException">
        /// stream
        /// or
        /// formatter
        /// </exception>
        public static void Write <T>(T obj, Stream stream, IDataFormatter <T> formatter, bool compress)
        {
            if (stream == null)
            {
                ThrowHelper.ThrowArgumentNullException("stream");
            }
            if (formatter == null)
            {
                ThrowHelper.ThrowArgumentNullException("formatter");
            }

            if (compress)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    formatter.Write(ms, obj);
                    COMPRESSION_FORMATTER.Write(stream, ms.ToArray());
                }
            }
            else
            {
                formatter.Write(stream, obj);
            }
        }