//Read public StatusControl this[double value] { get { try { StatusControl foundStatusControl = null; foreach (double statusControlKey in _statusControls.Keys) { if (foundStatusControl == null) { foundStatusControl = (StatusControl)_statusControls[statusControlKey]; } if (value < statusControlKey) { break; } foundStatusControl = (StatusControl)_statusControls[statusControlKey]; } if (foundStatusControl == null) { throw new KeyNotFoundException(); } if (foundStatusControl.IsValueInRange(value)) { return(foundStatusControl); } throw new KeyNotFoundException(); } catch (Exception ex) { throw new KeyNotFoundException("Can't find", ex); } } }
//Create public void Add(StatusControl statusControl) { if (Contains(statusControl)) { throw new ArgumentException("A status control covering all or a portion of that value range already exists"); } _statusControls.Add(statusControl.IsRange ? statusControl.TargetRange.Min : statusControl.TargetValue, statusControl); }
public bool Contains(StatusControl statusControl) { try { var unused = statusControl.IsRange ? this[statusControl.TargetRange.Min] : this[statusControl.TargetValue]; return(true); } catch (KeyNotFoundException exception) { return(false); } }
public void Remove(StatusControl statusControl) { var itemKey = statusControl.IsRange ? statusControl.TargetRange.Min : statusControl.TargetValue; var itemToDelete = this[itemKey]; if (itemToDelete.GetHashCode() == statusControl.GetHashCode()) { _statusControls.Remove(itemKey); } }
public bool ContainsValue(double value) { try { StatusControl foundStatusControl = null; foreach (var statusControlKey in _statusControls.Keys) { if (foundStatusControl == null) { foundStatusControl = (StatusControl)_statusControls[statusControlKey]; } if (value < statusControlKey) { break; } foundStatusControl = (StatusControl)_statusControls[statusControlKey]; } return(foundStatusControl != null && foundStatusControl.IsValueInRange(value)); } catch (Exception) { return(false); } }