/// <summary> /// Unregisters all commands from a <see cref="ICommandMethodsProvider"/>. /// </summary> /// <param name="provider">The command provider.</param> public void Unregister(ICommandMethodsProvider provider) { var r = GetCommands(provider.CommandProviderName.AppendPart("*")).ToList(); foreach (var p in r) { _commands.Remove(p.UniqueName); } }
/// <summary> /// Registers a <see cref="ICommandMethodsProvider"/> by analyzing its public methods. /// </summary> /// <param name="provider">The command provider.</param> public void Register(ICommandMethodsProvider provider) { var methods = provider?.GetType().GetMethods() ?? throw new ArgumentNullException(nameof(provider)); foreach (var m in methods) { var attr = m.GetCustomAttribute <CommandMethodAttribute>(); if (attr != null) { var enabled = GetEnabledMethod(provider, methods, m.Name); Register(attr.ConfirmationRequired, provider.CommandProviderName.AppendPart(m.Name), provider, m, enabled); } } }