Esempio n. 1
0
        public static Shell AddCommand(this Shell shell, string pattern, string description,
                                       InvokeShellCommandDelegate invokeHandler, CompleteShellCommandDelegate completeHandler)
        {
            if (shell == null)
            {
                throw new ArgumentNullException(nameof(shell));
            }
            if (invokeHandler == null)
            {
                throw new ArgumentNullException(nameof(invokeHandler));
            }

            var command = new ShellCommand(pattern, description);

            command.InvokeCommand +=
                (sender, args) => { invokeHandler(args.Shell, sender as IShellCommand, args.Arguments); };

            if (completeHandler != null)
            {
                command.CompleteCommand +=
                    (sender, args) =>
                {
                    args.Result = completeHandler(args.Shell, sender as IShellCommand, args.Tokens);
                };
            }

            return(shell.AddCommand(command));
        }
Esempio n. 2
0
        public static Shell AddCommand(this Shell shell, string pattern, string description,
            InvokeShellCommandDelegate invokeHandler, CompleteShellCommandDelegate completeHandler)
        {
            if (shell == null) throw new ArgumentNullException(nameof(shell));
            if (invokeHandler == null) throw new ArgumentNullException(nameof(invokeHandler));

            var command = new ShellCommand(pattern, description);
            command.InvokeCommand +=
                (sender, args) => { invokeHandler(args.Shell, sender as IShellCommand, args.Arguments); };

            if (completeHandler != null)
            {
                command.CompleteCommand +=
                    (sender, args) =>
                    {
                        args.Result = completeHandler(args.Shell, sender as IShellCommand, args.Tokens);
                    };
            }

            return shell.AddCommand(command);
        }