Xamarin.Forms Using Configuration Files
One things I have really appreciated as part of .Net projects is the configuration file which has allowed me to centralize settings and mutable values that I do not want scattered through my code. The ability for these configurations to be set based on environment or compilation state is also a must since values are determine based on deployment.
You can image my frustration that Xamarin projects do not have a default configuration file similar to web or windows applications. Well, this just won’t do and as a result, here is an implementation that might make your life a bit easier.
We first begin with creating a static class that read files that are set as embedded resources.
The next thing we need to do is create POCO objects that represent configuration settings we want to capture and set for the application. I started this process in reverse by creating my json file first with fake data and then going to json2csharp.com and having the site create the classes. I then pasted the class definitions into a single file called ConfigurationModels. I did this to provide a separation of concerns since this is an evolving process and I will probably being changing things in the future.
Once we have created the Models, we just need to create a singleton classes that loads the embedded resource file, parse it and read the values into public properties that can be accessed by the application.
You can see the entire working example on github. Download the reference guide project and CommonCore.
Hey Les thanks for introducing me to xamarin I'm going to be publishing my first app to the play store very soon.