Exemplo n.º 1
0
        /// <summary>
        /// Adds the specified command implementation to the manager,
        /// with the specified explicit metadata.
        /// </summary>
        /// <param name="command">The command instance, which does not need to
        /// be annotated with the <see cref="CommandAttribute"/> attribute since
        /// it's provided explicitly.</param>
        /// <param name="metadata">Explicit metadata to use for the command,
        /// instead of reflecting the <see cref="CommandAttribute"/>.</param>
        public void AddCommand(ICommandExtension command, CommandAttribute metadata)
        {
            Guard.NotNull(() => command, command);
            Guard.NotNull(() => metadata, metadata);

            var menuService = serviceProvider.GetService<IMenuCommandService>();
            var commandId = new CommandID(new Guid(metadata.GroupId), metadata.CommandId);
            var existing = menuService.FindCommand(commandId);

            if (existing != null)
                throw new ArgumentException(Strings.CommandManager.DuplicateCommand(metadata.CommandId, metadata.GroupId));

            menuService.AddCommand(new VsCommandExtensionAdapter(commandId, command));
            tracer.Info(Strings.CommandManager.CommandRegistered(command.Text, command.GetType()));
        }