// Method to set a property on an IRoutineSetting instance public static void SetPropertyOnSettingsInstance(List <SettingsToggleSetting> settings, IRoutineSettings settingsInstance, bool checkedOn) { // does the toggle have multiple settings? If so, we should try to iterate through the IRoutineSettings once // and change them at the same time if (settings.Count > 1) { foreach (var property in settingsInstance.GetType().GetProperties()) { var setting = settings.FirstOrDefault(r => r.Name == property.Name); if (setting == null) { continue; } SetValueOnProperty(property, setting, settingsInstance, checkedOn); } } else { var setting = settings.FirstOrDefault(); if (setting == null) { return; } SetValueOnProperty(settingsInstance.GetType().GetProperties().FirstOrDefault(r => r.Name == setting.Name), setting, settingsInstance, checkedOn); } }
public static IEnumerable <ToggleProperty> ExtractPropertyNamesAndTypesFromSettingsInstance(IRoutineSettings settings) { return(settings.GetType().GetProperties().Where(TypeIsValidType).Select(r => new ToggleProperty { Name = r.Name, Type = r.TypeToSettingType() }).ToList().OrderBy(r => r.Name)); }