public void SetToggleState() { // Sets the state of this current toggle to checked or unchecked if (Settings == null || !Settings.Any()) { Logging.Write($@"No Settings In Toggle: {ToggleText}"); return; } var settingsInstance = ToggleJob.GetIRoutineSettingsFromJobString(); var settingsProperties = settingsInstance.GetType().GetProperties(); foreach (var settingsToggleSetting in Settings) { // Find the property that matches the toggle setting var settingsProperty = settingsProperties.FirstOrDefault(r => r.Name == settingsToggleSetting.Name); // If there's no property, continue the loop if (settingsProperty == null) { continue; } // Check to see if the value on the property matches what our Checked value should be if (SettingsHandler.SettingToggleSettingMatchesProperty(settingsToggleSetting, settingsProperty, settingsInstance)) { continue; } // Toggle is unchecked because one of its properties does not match its checked value ToggleChecked = false; return; } // Toggle is checked because all properties match their checked values ToggleChecked = true; }