/// <summary> /// Reads the specified stream. /// </summary> /// <typeparam name="T">Generic type</typeparam> /// <param name="stream">The stream.</param> /// <param name="formatter">The formatter.</param> /// <param name="decompress">if set to <c>true</c> [decompress].</param> /// <returns>Data</returns> /// <exception cref="System.ArgumentNullException"> /// stream /// or /// formatter /// </exception> public static T Read <T>(Stream stream, IDataFormatter <T> formatter, bool decompress) { if (stream == null) { ThrowHelper.ThrowArgumentNullException("stream"); } if (formatter == null) { ThrowHelper.ThrowArgumentNullException("formatter"); } T result = default(T); if (decompress) { using (MemoryStream ms = new MemoryStream(COMPRESSION_FORMATTER.Read(stream))) { result = formatter.Read(ms); } } else { result = formatter.Read(stream); } return(result); }