Portable Class Library Setup Information

I have a portable class library that I need to get in the application that hosts its settings.

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

Is there any way to do this. I searched like crazy, and I can’t find anything that will allow me to read this information, and I can’t find anything that will tell me where the application configuration file is even located.

Are there any suggestions on how to agnostically read application settings in PCL?

+4
source share
4 answers

You cannot do this directly from the portable library. I would recommend using an abstraction pattern. Create an interface (e.g. IApplicationSettings or something else), encapsulating the functionality needed for access. Then, the platform library for each platform implements this interface using the platform parameter APIs. Pass the implementation instance from platform-specific code to portable code so that it can access this function.

More information can be found in this blog: How to make portable class libraries for you

+2
source

Create an open class in your PCL with members for the data you need PCL. Applications that consume your PCL libraries populate an instance of this class with the necessary data from their environment and pass it to the PCL code that needs these values.

+2
source

Perhaps: I implemented a PCL library that provides exactly what you are looking for. Take a look:

The class works for WinRT, WP8 and WPF / desktop applications. Inside, it uses reflection to invoke the correct api depending on the current platform.

+2
source

It is not possible to read these parameters from the portable class library.

You can instantiate your own class in your PCL and populate it outside.

+1
source

All Articles