Anthony Nichols Anthony Nichols - 3 months ago 27
C# Question

StreamReader and Portable Class Library

I am writing a ConfigManager class using Portable Class Libraries. PCL supports

StreamReader
and
StreamWriter
classes that I want to use, but the PCL version of those classes do not support passing in a string during construction. PCL also does not support the
reader.Close()
and
writer.Close()
. Lastly it doesn't support the
FileStream
class.

So I am looking for an answer to any one of the following questions:


  1. How can I get the
    StreamReader
    and
    StreamWriter
    classes working
    in a PCL?

  2. How can I create a new
    stream
    using PCL?

  3. What other alternitives do I have to load and save files in a PCL?


Answer

Use Dispose() instead of Close() (or just wrap everything in a using statement). We've hidden/removed Close() in Windows Store apps and newer PCLs, because it does the same thing and people would be confused about which one to call.

Consider using PCL Storage for cross platform file system access.

Here are some blog posts you may want to refer to for how to approach platform-specific functionality in PCLs: