Exemple #1
0
        public bool UnloadCommands()
        {
            if (_commandAssemblyLoadContext == null)
            {
                return(true);
            }

            _commandTypes.Clear();
            _commandTypes = null;

            GC.Collect(); //lgtm [cs/call-to-gc]

            bool result = _commandAssemblyLoadContext.Unload();

            _commandAssemblyLoadContext = null;

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Loads commands from an assembly without locking the assembly
        /// </summary>
        /// <param name="commandAssemblyFile">Filepath</param>
        /// <returns>Commands loaded</returns>
        public bool LoadCommands(string commandAssemblyFile)
        {
            _commandAssemblyLoadContext = new CommandAssemblyLoadContext();
            _commandTypes = new ConcurrentDictionary <string, ICommand>();

            if (!_commandAssemblyLoadContext.Load(commandAssemblyFile))
            {
                return(false);
            }

            foreach (Type t in _commandAssemblyLoadContext.Assembly.GetTypes())
            {
                if (t.GetInterface(nameof(ICommand)) == null)
                {
                    continue;
                }

                RegisterCommand(t);
            }

            return(true);
        }