Xamarin App, where do you keep Config Values?

Install the nuget package(Settings Plugin) first https://www.nuget.org/packages/Xam.Plugins.Settings/

Settings.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

using Plugin.Settings;
using Plugin.Settings.Abstractions;
namespace App4
{
public static class Settings
{
private static ISettings AppSettings
{
get { return CrossSettings.Current; }
}

private const string UserNameKey = “Username”;
private static readonly string UserNameDefault = “asish”;
public static string UserName
{
get { return AppSettings.GetValueOrDefault(UserNameKey, UserNameDefault); }
set { AppSettings.AddOrUpdateValue(UserNameKey, value); }
}
private const string UserPasswordKey = “Password”;
private static readonly string UserPasswordDefault = “punnose”;
public static string UserPassword
{
get { return AppSettings.GetValueOrDefault(UserPasswordKey, UserPasswordDefault); }
set { AppSettings.AddOrUpdateValue(UserPasswordKey, value); }
}

}
}

How to call config values in Xamarin android or iOS classes?

string LoginEmailId;
string LoginPassword;

if (Settings.UserName != null && Settings.UserPassword != null)
{
LoginEmailId = Settings.UserName;
LoginPassword = Settings.UserPassword;
}

 

Add Comment