static void SafeExecute( this ICommand command, MouseState state, object parameter ) { var args = new MouseCommandArgs { MouseState = state, Parameter = parameter }; if ( command != null && command.CanExecute( args ) ) { command.Execute( args ); } }
public static bool CanDebug (this ProjectOperations opers, IBuildTarget entry) { ExecutionContext context = new ExecutionContext (DebuggingService.GetExecutionHandler (), IdeApp.Workbench.ProgressMonitors, IdeApp.Workspace.ActiveExecutionTarget); return opers.CanExecute (entry, context); }
public static bool CanExecute( this ICommand command ) { Arg.NotNull( command, nameof( command ) ); return command.CanExecute( null ); }
/// <summary> /// Returns an observable sequence that indicates when the <paramref name="command"/> can be executed, /// starting with the current state of the <paramref name="command"/>. /// </summary> /// <remarks> /// The observable is a sequence of values returned by <see cref="ICommand.CanExecute"/> /// whenever the <paramref name="command"/> raises its <see cref="ICommand.CanExecuteChanged"/> event. /// </remarks> /// <param name="command">The <see cref="ICommand"/> to be observed.</param> /// <param name="parameter">The object that is passed to the <see cref="ICommand.CanExecute"/> method. /// This value can be <see langword="null"/> if the <paramref name="command"/> supports it.</param> /// <returns>An observable sequence that indicates when the <paramref name="command"/> can be executed, /// starting with the current state of the <paramref name="command"/>.</returns> public static IObservable<bool> CanExecuteObservable( this ICommand command, object parameter) { Contract.Requires(command != null); Contract.Ensures(Contract.Result<IObservable<bool>>() != null); return Observable.FromEventPattern( handler => command.CanExecuteChanged += handler, handler => command.CanExecuteChanged -= handler) .Select(_ => command.CanExecute(parameter)) .Publish(command.CanExecute(parameter)) .RefCount() .DistinctUntilChanged(); }
public static void VerifyAndExecute(this ICommand command, object parameter) { if (command != null && command.CanExecute(parameter)) { command.Execute(parameter); } }
/// <summary> /// Executes if the specified <see cref="ICommand"/> with the specified argument if it can be executed. /// </summary> /// <param name="command">The command to try to execute.</param> /// <param name="arg">The arg specified in the command.</param> public static void TryExecute(this ICommand command, object arg) { if (command.CanExecute(arg)) { command.Execute(arg); } }
public static void ExecuteIfCan(this IReactiveCommand @this, object o) { if (@this == null) return; if (@this.CanExecute(o)) @this.Execute(o); }
/// <summary>Executes a command if it is able.</summary> public static void ExecuteIfCan(this ICommand command, object parameter) { if (command == null) return; if (command.CanExecute(parameter)) command.Execute(parameter); }
public static bool TryExecute(this ICommand command, object parameter = null) { var canExecute = command.CanExecute(parameter); if (canExecute) { command.Execute(parameter); } return canExecute; }
public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events) { var ev = new EventHandler((o,e) => { if (!This.CanExecute(null)) return; This.Execute(null); }); control.AddTarget(ev, events); return Disposable.Create(() => control.RemoveTarget(ev, events)); }
public static bool TryExecute(this ICommand command, object parameter) { if (command.CanExecute(parameter)) { command.Execute(parameter); return true; } return false; }
public static IDisposable BindToTarget(this ICommand This, View control) { var ev = new EventHandler((o, e) => { if (!This.CanExecute(null)) return; This.Execute(null); }); var cech = new EventHandler((o, e) => { var canExecute = This.CanExecute(null); control.Enabled = canExecute; }); This.CanExecuteChanged += cech; control.Click += ev; control.Enabled = This.CanExecute(null); return Disposable.Create(() => { This.CanExecuteChanged -= cech; control.Click -= ev; }); }
public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events) { var ev = new EventHandler((o,e) => { if (!This.CanExecute(null)) return; This.Execute(null); }); var cech = new EventHandler((o, e) => { var canExecute = This.CanExecute(null); control.Enabled = canExecute; }); This.CanExecuteChanged += cech; control.AddTarget(ev, events); control.Enabled = This.CanExecute(null); return Disposable.Create(() => { control.RemoveTarget(ev, events); This.CanExecuteChanged -= cech; }); }
/// <summary> /// Will call the Execute method for a command, iff the command can execute. /// </summary> /// <param name="command">Command to execute.</param> public static void ExecuteIfCan(this ICommand command) { if (command.CanExecute()) command.Execute(); }
public static void TryExecute(this ICommand command, object parameter) { if (command.CanExecute(parameter)) command.Execute(parameter); }
static void SafeExecute( this ICommand command, object parameter ) { if ( command != null && command.CanExecute( null ) ) { command.Execute( parameter ); } }
static void SafeExecute( this ICommand dragCommand, ClickDragInfo dragInfo, object parameter ) { var args = new MouseDragCommandArgs { DragInfo = dragInfo, Parameter = parameter }; if ( dragCommand != null && dragCommand.CanExecute( args ) ) { dragCommand.Execute( args ); } }
public static void ExecuteAsync(this DefaultableCompositeCommand command, object arg) { if (command.CanExecute(arg)) { command.Execute(arg); } }
/// <summary> /// Raises an appropriate ScriptRuntimeException if the specified access is not supported. /// Checks are made for the MemberDescriptorAccess permissions AND for the access of instance /// members through static userdatas. /// </summary> /// <param name="desc">The desc.</param> /// <param name="access">The access.</param> /// <param name="obj">The object to be checked for access.</param> public static void CheckAccess(this IMemberDescriptor desc, MemberDescriptorAccess access, object obj) { if (!desc.IsStatic && obj == null) throw ScriptRuntimeException.AccessInstanceMemberOnStatics(desc); if (access.HasAllFlags(MemberDescriptorAccess.CanExecute) && !desc.CanExecute()) throw new ScriptRuntimeException("userdata member {0} cannot be called.", desc.Name); if (access.HasAllFlags(MemberDescriptorAccess.CanWrite) && !desc.CanWrite()) throw new ScriptRuntimeException("userdata member {0} cannot be assigned to.", desc.Name); if (access.HasAllFlags(MemberDescriptorAccess.CanRead) && !desc.CanRead()) throw new ScriptRuntimeException("userdata member {0} cannot be read from.", desc.Name); }
public static void ExecuteIfItCan(this ICommand cmd, object parameter = null) { if (cmd.CanExecute(parameter)) cmd.Execute(parameter); }
public static bool CanExecute(this ICommand command) { return command.CanExecute(null); }
public static ICommand AllowWhenNoErrors(this ICommand command, IDataErrorInfo viewModel) { return new DelegateCommand(command.Execute, x => string.IsNullOrWhiteSpace(viewModel.Error) && command.CanExecute(x)); }
public static void ExecuteIfCan(this ICommand @this, object o) { if (@this.CanExecute(o)) @this.Execute(o); }