Rob <Ro*@discussions.microsoft.com> wrote:
I have a streamwriter that may get closed. The writer is passed into another
class by ref and is consumed there. What can happen is that the writer might
get closed by the spawning class.
Is there a way to extract the path of the streamwriter passed in by ref? I
don't see a property for it, but there might be a work around someone has.
No, because there may not *be* a path. (What would the StreamWriter for
a writer to a MemoryStream be?)
What you *can* do is use the StreamWriter.BaseStream to get the
underlying stream, and then if that's a FileStream you can use
FileStream.Name to access the path.
I'm not sure why you've mentioned twice that the StreamWriter is being
passed by reference - it's irrelevant here, even if it's true. I
*suspect* that it's not actually being passed by reference, however -
or at least doesn't need to be. It's worth understanding parameter
passing thoroughly. See
http://www.pobox.com/~skeet/csharp/parameters.html for more
information.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too