示例#1
0
文件: XmlFu.cs 项目: zweib730/beagrep
		public static void SerializeUtf8 (XmlSerializer serializer, Stream stream, object o)
		{
			if (serializer == null)
				throw new ArgumentNullException ("serializer");

			if (stream == null)
				throw new ArgumentNullException ("stream");

			if (o == null)
				throw new ArgumentNullException ("o");

			UnclosableStream unclosable_stream = new UnclosableStream (stream);
			BufferedStream buffered_stream = new BufferedStream (unclosable_stream, 8192);

			Stopwatch w = new Stopwatch ();
			w.Start ();
			XmlTextWriter xml_writer = new XmlTextWriter (buffered_stream, Encoding.UTF8);
			xml_writer.Formatting = Formatting.Indented;
			serializer.Serialize (xml_writer, o);

			// This will flush the stream and release the buffer.
			// Normally it also closes the underlying stream,
			// which is why it wraps an UnclosableStream.
			buffered_stream.Dispose ();
			w.Stop ();

			if (Debug)
				Log.Debug (">>> Serialization of {0}: {1}", o.GetType (), w);
		}
示例#2
0
        public static void SerializeUtf8(XmlSerializer serializer, Stream stream, object o)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (o == null)
            {
                throw new ArgumentNullException("o");
            }

            UnclosableStream unclosable_stream = new UnclosableStream(stream);
            BufferedStream   buffered_stream   = new BufferedStream(unclosable_stream, 8192);

            Stopwatch w = new Stopwatch();

            w.Start();
            XmlTextWriter xml_writer = new XmlTextWriter(buffered_stream, Encoding.UTF8);

            xml_writer.Formatting = Formatting.Indented;
            serializer.Serialize(xml_writer, o);

            // This will flush the stream and release the buffer.
            // Normally it also closes the underlying stream,
            // which is why it wraps an UnclosableStream.
            buffered_stream.Dispose();
            w.Stop();

            if (Debug)
            {
                Log.Debug(">>> Serialization of {0}: {1}", o.GetType(), w);
            }
        }