TopShelfCustomer/TopShelfCustomer/ViewModels/SettingsViewModel.cs
/// <summary>
/// ToggleSwitchSetting:
///
/// Takes the name of a UserSettings property and a value,
/// then finds that property by name and sets it to value.
/// Then writes the modified userSettings object to user settings file as JSON.
/// </summary>
/// <param name="settingProperty"> The name of the property to set on userSettings </param>
/// <param name="value"> The bool value to assign the property </param>


Takes the name of a UserSettings property and a value,
then finds that property by name and sets it to value.
Then writes the modified userSettings object to user settings file as JSON.
Takes the name of a UserSettings property and a value then finds that property by name and sets it to value . Then writes the modified userSettings object to user settings file as JSON .
private void ToggleSwitchSetting ( string settingProperty, bool value ) {
                Type objectType = SettingsContainer.CurrentUserSettings.GetType();      
                PropertyInfo objectPropertyInfo = objectType.GetProperty( settingProperty );        
                if ( objectPropertyInfo != null && objectPropertyInfo.CanWrite ) {
                    objectPropertyInfo.SetValue( SettingsContainer.CurrentUserSettings, value, null );      
                }
                string userSettingsPath = SettingsContainer.SettingsFilePath + UserContainer.CurrentUser.Id;        
                jsonObject = JObject.FromObject( SettingsContainer.CurrentUserSettings );        
                SerializationHelper.JsonWrite( userSettingsPath, jsonObject.ToString() );       
            }
private void ToggleSwitchSetting ( string settingProperty , bool value ) { Type objectType = SettingsContainer . CurrentUserSettings . GetType ( ) ; PropertyInfo objectPropertyInfo = objectType . GetProperty ( settingProperty ) ; if ( objectPropertyInfo != null && objectPropertyInfo . CanWrite ) { objectPropertyInfo . SetValue ( SettingsContainer . CurrentUserSettings , value , null ) ; } string userSettingsPath = SettingsContainer . SettingsFilePath + UserContainer . CurrentUser . Id ; jsonObject = JObject . FromObject ( SettingsContainer . CurrentUserSettings ) ; SerializationHelper . JsonWrite ( userSettingsPath , jsonObject . ToString ( ) ) ; }
ToggleSwitchSetting:
ToggleSwitchSetting :
//Get the Type of both userSettings //Get the property to set from UserSettings //Set the value of userSettings //Modify path to set this User's settings //Create JSON object from userSettings //Write the JSON object to the settings file
settingProperty
string
The name of the property to set on userSettings
The name of the property to set on userSettings
value
bool
The bool value to assign the property
The bool value to assign the property