Search code examples
c#portable-class-libraryapplication-settings

Portable Class Library Read Settings Info


I have a portable class library that I need to get at the application that is hosting it's settings.

(i.e. web.config, app.config or Windows (phone) 8 settings wherever those are stored)

Is there a way to do this .I've been searching like crazy and can't find anything that allows me to read this information, and I can't find anything that will tell me where the application config file is located even.

Anyone have any suggestions on how to agnostic-ally read application settings in a PCL?


Solution

  • You can't do this directly from a portable library. I'd recommend using the abstraction pattern. Create an interface (ie IApplicationSettings or something) encapsulating the functionality you need to access. Then in a platform-specific library for each platform implement that interface using the platform-specific settings APIs. Pass an instance of the implementation from platform-specific code to the portable code so it can access that functionality.

    More details can be found in this blog post: How to Make Portable Class Libraries Work for You