/// <summary> /// Registers a new class. The class will be searched through with reflection. /// </summary> /// <typeparam name="T">The Type of the Class</typeparam> /// <param name="instance">The instance of the class on which the console will invoke the methods.</param> /// <param name="className">A custom classname which will be the prefix for the command for example Class.DoSometing when null the name of the class will be used. Usefull if more than one instance of a class are registerd in the console.</param> /// <param name="importType">Import Type: /// Public : Import all Public Methods /// Marked (default) : Import only Methods with the ConsoleCommand attribute /// </param> public void RegisterClass <T>(object instance, string className = null, ReflectionHelper.ImportType importType = ReflectionHelper.ImportType.Marked) { foreach (var cmd in ReflectionHelper.GetCommands(typeof(T), instance, importType, className)) { RegisterCommand(cmd); } }
/// <summary> /// Removes all commands registered from a class. /// </summary> /// <typeparam name="T">The Type of the Class</typeparam> /// <param name="instance">The instance of the class.</param> /// <param name="className">The registred class name</param> /// <param name="importType">Use the same import type here as you used on register</param> public void DeregisterClass <T>(object instance, string className = null, ReflectionHelper.ImportType importType = ReflectionHelper.ImportType.Marked) { foreach (var cmd in ReflectionHelper.GetCommands(typeof(T), instance, importType, className)) { if (_registeredCommands.ContainsKey(cmd.CommandName)) { DeregisterCommand(cmd.CommandName); } } }