/// <summary> /// Performs an action and send back a Disposable which will perform another action once it is disposed. Typically used to make temporary changes through /// the "using" pattern. /// </summary> /// <param name="push">The action to perform right now</param> /// <param name="pop">The action to perform once the returned object will be disposed</param> /// <returns>An object implementing IDisposable</returns> /// <exception cref="System.ArgumentNullException">push</exception> public static IDisposable Begin(Action push, Action pop) { push.ThrowIfNull(nameof(push)); push(); return new DisposableWithCallback(pop); }
public MessageInputHandler(WorldInstance worldInstance, MessageRendererState messageRendererState, TimeSpan totalTime, Action<IXnaGameTime> messageClosingDelegate) { worldInstance.ThrowIfNull("worldInstance"); messageRendererState.ThrowIfNull("messageRendererState"); messageClosingDelegate.ThrowIfNull("messageClosingDelegate"); _worldInstance = worldInstance; _messageRendererState = messageRendererState; _messageClosingDelegate = messageClosingDelegate; _answerKeyboardStateHelper = new KeyboardStateHelper( KeyDown, null, null, TextAdventure.Xna.Constants.MessageRenderer.Input.AcceptKey, TextAdventure.Xna.Constants.MessageRenderer.Input.NextAnswerKey, TextAdventure.Xna.Constants.MessageRenderer.Input.PreviousAnswerKey); _scrollKeyboardStateHelper = new KeyboardStateHelper( _scrollKeyboardRepeatHelper, TextAdventure.Xna.Constants.MessageRenderer.Input.ScrollUpKey, TextAdventure.Xna.Constants.MessageRenderer.Input.ScrollDownKey, TextAdventure.Xna.Constants.MessageRenderer.Input.HomeKey, TextAdventure.Xna.Constants.MessageRenderer.Input.EndKey, TextAdventure.Xna.Constants.MessageRenderer.Input.PageUpKey, TextAdventure.Xna.Constants.MessageRenderer.Input.PageDownKey); _scrollKeyboardRepeatHelper.InitialInterval = TextAdventure.Xna.Constants.MessageRenderer.Input.ScrollKeyboardInterval; _scrollKeyboardRepeatHelper.RepeatingInterval = TextAdventure.Xna.Constants.MessageRenderer.Input.ScrollKeyboardInterval; }
/// <summary> /// Invokes asynchronously the specified action for this control. /// </summary> /// <param name="control">The control.</param> /// <param name="action">The action.</param> public static void BeginInvoke(Control control, Action action) { control.ThrowIfNull("control"); action.ThrowIfNull("action"); if (!control.Created || control.IsDisposed || !control.IsHandleCreated) return; control.BeginInvoke(action); }
public CssCommentaryInterpreter(Action<Int32, Int32> onOpen, Action<String, Int32, Int32> onClose) { onOpen.ThrowIfNull("onOpen"); onClose.ThrowIfNull("onClose"); this.onOpen = onOpen; this.onClose = onClose; }
public ReactiveCommand( Action<object> execute, Func<object, bool> canExecute, params INotifyPropertyChanged[] canExecuteNotifiers) { _execute = execute.ThrowIfNull(); _canExecute = canExecute.ThrowIfNull(); _canExecuteNotifiers = canExecuteNotifiers; _canExecuteNotifiers.ForEach(x => x.SubscribeWeakly(this, (c, s, e) => c.NotifyCanExecuteChanged())); }
public WeakAction(Action action) { action.ThrowIfNull("action"); _method = action.GetMethodInfo(); if (action.GetMethodInfo().IsStatic) { _staticAction = action; } if (action.Target != null) { _actionTargetReference = new WeakReference(action.Target); } }
public MessageFadeOutAndScaleUpdater(MessageRendererState messageRendererState, TimeSpan totalTime, Action completeDelegate) { messageRendererState.ThrowIfNull("messageRendererState"); completeDelegate.ThrowIfNull("completeDelegate"); if (totalTime < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("totalTime"); } _messageRendererState = messageRendererState; _completeDelegate = completeDelegate; _timedLerpHelper = new TimedLerpHelper(totalTime, TextAdventure.Xna.Constants.MessageRenderer.FadeOutDuration, 1f, 0f); }
public TimerHelper(TimeSpan startTotalTime, TimeSpan duration, Action completedDelegate) { completedDelegate.ThrowIfNull("completedDelegate"); if (startTotalTime < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("startTotalTime"); } if (duration < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("duration"); } _duration = duration; _startTotalTime = startTotalTime; _completedDelegate = completedDelegate; }
/// <summary> /// Invokes the specified action for this control. /// </summary> /// <param name="control">The control.</param> /// <param name="action">The action.</param> public static void Invoke(Control control, Action action) { control.ThrowIfNull("control"); action.ThrowIfNull("action"); if (!control.Created || control.IsDisposed || !control.IsHandleCreated) return; try { control.Invoke(action); } catch (ObjectDisposedException ex) { logger.LogError("Control {0} disposed while trying to process an Invoke on it".InvariantFormat(control.Name)); logger.LogException(ex); } catch (InvalidOperationException ioe) { logger.LogError("Invalid operation exception triggered by {0} control while trying to invoke".InvariantFormat(control.Name)); logger.LogException(ioe); } }
private void Transaction(Action<IDbConnection, IDbTransaction> action) { action.ThrowIfNull("action"); using(var conn = this.GetConnection()) { using(var tx = conn.BeginTransaction()) { try { action(conn, tx); tx.Commit(); } catch { tx.Rollback(); throw; } } } }
/// <summary> /// Saves the blank character. /// </summary> /// <param name="callback">The callback.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">callback</exception> public static async Task SaveAsync(Action callback) { callback.ThrowIfNull(nameof(callback)); SerializableCCPCharacter serial = CreateCharacter(); using (SaveFileDialog fileDialog = new SaveFileDialog()) { fileDialog.Title = @"Save Blank Character"; fileDialog.Filter = @"Blank Character CCPXML (*.xml) | *.xml"; fileDialog.FileName = $"{serial.Name}.xml"; fileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); DialogResult result = fileDialog.ShowDialog(); if (result != DialogResult.OK) return; XmlDocument xmlDoc = (XmlDocument)Util.SerializeToXmlDocument(serial); string content = Util.GetXmlStringRepresentation(xmlDoc); await FileHelper.OverwriteOrWarnTheUserAsync(fileDialog.FileName, async fs => { using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8)) { await writer.WriteAsync(content); await writer.FlushAsync(); await fs.FlushAsync(); } return true; }); s_filename = fileDialog.FileName; callback.Invoke(); } }
public RelayCommand(Action<object> execute, Predicate<object> canExecute) { this.execute = execute.ThrowIfNull(); this.canExecute = canExecute; }
public RelayCommand(Action<object> execute, Predicate<object> canExecute) { execute.ThrowIfNull("execute"); _execute = execute; _canExecute = canExecute; }
/// <summary> /// Adds the plans as toolstrip items to the list. /// </summary> /// <param name="plans">The plans.</param> /// <param name="list">The list.</param> /// <param name="initialize">The initialize.</param> /// <exception cref="System.ArgumentNullException"></exception> public static void AddTo(this IEnumerable<Plan> plans, ToolStripItemCollection list, Action<ToolStripMenuItem, Plan> initialize) { plans.ThrowIfNull(nameof(plans)); list.ThrowIfNull(nameof(list)); initialize.ThrowIfNull(nameof(initialize)); //Scroll through plans foreach (Plan plan in plans) { ToolStripMenuItem item; using (ToolStripMenuItem planItem = new ToolStripMenuItem(plan.Name)) { initialize(planItem, plan); item = planItem; } list.Add(item); } }
/// <summary> /// Creates a new DelegateAuthenticator. /// </summary> /// <param name="modifyRequest">Delegate used to modify the webrequest.</param> public DelegateAuthenticator(Action<HttpWebRequest> modifyRequest) { modifyRequest.ThrowIfNull("modifyRequest"); ModifyRequestDelegate = modifyRequest; }
/// <summary> /// Initializes a new instance of the <see cref="Disposable"/> class. /// </summary> /// <param name="action">The action.</param> public OnDisposeAction(Action action) { action.ThrowIfNull("action"); Action = action; }
public Command(Action<object> action, Predicate<object> canExecute) { this.action = action.ThrowIfNull("Command : action null"); this.canExecute = canExecute.ThrowIfNull("Command : canExecute null"); }
public Command(Action<object> action, Predicate<object> canExecute = null) { this.action = action.ThrowIfNull("Command : action null"); this.canExecute = canExecute; this.isEnabled = true; }