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:
StreamReader
and StreamWriter
classes working
in a PCL?stream
using PCL? 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:
found the answer over here (by Rob Caplan): http://social.msdn.microsoft.com/Forums/windowsapps/en-US/386eb3b2-e98e-4bbc-985f-fc143db6ee36/read-local-file-in-portable-library#386eb3b2-e98e-4bbc-985f-fc143db6ee36
File access cannot be done portably between Windows Store apps and Windows Phone 8 apps. You will have to use platform specific code, to open the file and acquire a stream. You can then pass the stream into the PCL.
Since both Windows Store apps and Windows Phone 8 apps use the essentially the same Windows (Phone) Runtime classes from Windows.Storage to open files you can share the code (but not the binary) by linking a code file between the two projects. See Share code with Add as Link .
See Maximize code reuse between Windows Phone 8 and Windows 8 for more techniques for sharing code.
If anyone has a solution other than this I would be interested to hear it; also wondering about the .Close()
methods in the PCL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With