System.IO.MemoryStream.WriteTo C# (CSharp) Méthode

WriteTo() public méthode

public WriteTo ( Stream stream ) : void
stream Stream
Résultat void
        public virtual void WriteTo(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream), SR.ArgumentNull_Stream);
            }
            if (!_isOpen)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
            }

            stream.Write(_buffer, _origin, _length - _origin);
        }
    }

Usage Example

Exemple #1
0
        public static void Main(string[] args)
        {
            try
            {
                string assName = args [0];
                string outFile = Path.GetDirectoryName (Assembly.GetEntryAssembly ().CodeBase).Substring (5) + "/" + Path.GetFileName (args [0]) + ".xml";
                string htmlFile = outFile.Replace (".xml", ".html");

                XmlSerializer xs = new XmlSerializer (typeof(ReflectedContainer));
                ReflectedAssembly ass = new ReflectedAssembly (assName);

                Console.Write (string.Format ("Output XML reflection for {0} (to console and to {1})\n [Y/n] ?", assName, outFile));
                ConsoleKey input = Console.ReadKey ().Key;
                if (input != ConsoleKey.N)
                {
                    Console.WriteLine ("\n");
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (XmlWriter xw = XmlWriter.Create (ms, XWSettings))
                        {
                            xs.Serialize (xw, new ReflectedContainer () { Assembly = ass });
                        }

                        if (File.Exists (outFile))
                            File.Delete (outFile);
                        using (Stream fs = File.OpenWrite (outFile), cs = Console.OpenStandardOutput ())
                        {
                            ms.WriteTo (fs);
                            ms.WriteTo (cs);
                        }

            //						if (File.Exists (htmlFile))
            //							File.Delete (htmlFile);
            //						using (Stream hs = File.OpenWrite (htmlFile))
            //						{
            //							using (XmlWriter xw = XmlWriter.Create(hs, XWSettings))
            //							{
            //								foreach (ReflectedType rt in ass.Types)
            //									rt.WriteHtml(xw);
            //							}
            //						}
                    }
                }
                else
                    Console.WriteLine ("Cancelled, exiting..");
            }
            catch (Exception ex)
            {
                Console.WriteLine ("! Exception : " + ex.ToString () + " : " + ex.Message);
            }
            finally
            {

            }
        }
All Usage Examples Of System.IO.MemoryStream::WriteTo