title: Is there any way to close a StreamWriter without closing its BaseStream?
body: <p>My root problem is that when <code>using</code> calls <code>Dispose</code> on a <code>StreamWriter</code>, it also disposes the <code>BaseStream</code> (same problem with <code>Close</code>).</p>
  
  <p>I have a workaround for this, but as you can see, it involves copying the stream. Is there any way to do this without copying the stream?</p>
  
  <p>The purpose of this is to get the contents of a string (originally read from a database) into a stream, so the stream can be read by a third party component.<br>
  <strong>NB</strong>: I cannot change the third party component.</p>
  
  <pre><code>public System.IO.Stream CreateStream(string value)
  {
      var baseStream = new System.IO.MemoryStream();
      var baseCopy = new System.IO.MemoryStream();
      using (var writer = new System.IO.StreamWriter(baseStream, System.Text.Encoding.UTF8))
      {
          writer.Write(value);
          writer.Flush();
          baseStream.WriteTo(baseCopy); 
      }
      baseCopy.Seek(0, System.IO.SeekOrigin.Begin);
      return baseCopy;
  }
  </code></pre>
  
  <p>Used as</p>
  
  <pre><code>public void Noddy()
  {
      System.IO.Stream myStream = CreateStream("The contents of this string are unimportant");
      My3rdPartyComponent.ReadFromStream(myStream);
  }
  </code></pre>
  
  <p>Ideally I'm looking for an imaginary method called <code>BreakAssociationWithBaseStream</code>, e.g.</p>
  
  <pre><code>public System.IO.Stream CreateStream_Alternate(string value)
  {
      var baseStream = new System.IO.MemoryStream();
      using (var writer = new System.IO.StreamWriter(baseStream, System.Text.Encoding.UTF8))
      {
          writer.Write(value);
          writer.Flush();
          writer.BreakAssociationWithBaseStream();
      }
      return baseStream;
  }
  </code></pre>