Mercurial > servermonitor
diff ServerMonitor/Controls/CheckControl.cs @ 9:7127d5b5ac75
Code cleanup and comments
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 08 Apr 2019 21:29:54 -0400 |
parents | 3142e52cbe69 |
children |
line wrap: on
line diff
--- a/ServerMonitor/Controls/CheckControl.cs Sat Mar 09 20:14:03 2019 -0500 +++ b/ServerMonitor/Controls/CheckControl.cs Mon Apr 08 21:29:54 2019 -0400 @@ -1,18 +1,16 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; using System.Data; using System.Linq; -using System.Text; using System.Windows.Forms; namespace ServerMonitorApp { - /// <summary>Base class for check controls</summary> + /// <summary>Base class for check controls.</summary> /// <remarks>This control should never be used directly, but marking it abstract causes problems with the designer.</remarks> public partial class CheckControl : UserControl { + /// <summary>Type of the check this control can edit.</summary> public Type CheckType => GetCheckType(GetType()); public CheckControl() @@ -24,6 +22,8 @@ { CheckGroupBox.Text = Helpers.GetDisplayName(CheckType); + // Bind change listeners to checkboxes to enable or disable a panel of controls. + // The leftmost checkbox is assumed to be the "master switch" for the panel. IEnumerable<Panel> panels = CheckGroupBox.Controls.OfType<Panel>(); foreach (Panel panel in panels) { @@ -41,6 +41,8 @@ DisablePanelByCheckBox((CheckBox)sender); } + /// <summary>Enables or disables all sibling controls of a checkbox.</summary> + /// <param name="checkBox">The checkbox to disable or enable the sibling controls of.</param> private void DisablePanelByCheckBox(CheckBox checkBox) { foreach (Control control in checkBox.Parent.Controls) @@ -50,16 +52,24 @@ } } + /// <summary>Sets the values of the controls from a check's properties.</summary> + /// <remarks>Subclasses should implement this method. Marking as abstract causes problems with the designer.</remarks> public virtual void LoadCheck(Check check) { } + /// <summary>Updates the properties of a check from user input.</summary> + /// <remarks>Subclasses should implement this method. Marking as abstract causes problems with the designer.</remarks> public virtual void UpdateCheck(Check check) { } + /// <summary>Creates an instance of a check control based on a check type.</summary> public static CheckControl Create(Type CheckType) { + // Use reflection to find a check control that declares it handles the given type. Type checkControlType = typeof(CheckControl).Assembly.GetTypes().FirstOrDefault(t => GetCheckType(t) == CheckType); + // If one was found, instantiate it. return checkControlType == null ? null : (CheckControl)Activator.CreateInstance(checkControlType); } + /// <summary>Gets the value of the CheckTypeAttribute for a type.</summary> private static Type GetCheckType(Type type) { return type.GetAttribute<CheckTypeAttribute>()?.CheckType;