/// <summary> /// Safely calls event. /// </summary> /// <param name="amountModifiedEventHandler">Event to call.</param> private static void CallEvent(AmountModifiedEventHandler amountModifiedEventHandler) { var handler = amountModifiedEventHandler; if (handler != null) { handler(); } }
/// <summary> /// Removes a callback from more than event dictionary at the given threshold. /// </summary> /// <param name="threshold">The threshold.</param> /// <param name="callback">The callback.</param> /// <param name="remove">Removes the event at the threshold key if true.</param> public void OffMoreThan(int threshold, AmountModifiedEventHandler callback, bool remove = true) { if (!moreThanEvents.ContainsKey(threshold)) { return; } // ReSharper disable once DelegateSubtraction moreThanEvents[threshold] -= callback; if (remove) { moreThanEvents.Remove(threshold); } }
/// <summary> /// Registers a callback to call when the value is more than the given threshold. /// </summary> /// <param name="threshold">The threshold.</param> /// <param name="callback">The callback.</param> public void OnMoreThan(int threshold, AmountModifiedEventHandler callback) { moreThanEvents.Add(threshold, null); moreThanEvents[threshold] += callback; }