Beispiel #1
0
        /// <summary>
        /// Retrieve a command info object about a command.
        /// </summary>
        /// <param name="commandName">Name of the command to get a commandinfo object for.</param>
        /// <param name="commandTypes">What types of command are needed. If omitted, all types are retrieved.</param>
        /// <returns></returns>
        public CommandInfo GetCommandInfo(string commandName, CommandTypes?commandTypes = null)
        {
            if (string.IsNullOrWhiteSpace(commandName))
            {
                return(null);
            }

            var key = new CommandLookupKey(commandName, commandTypes);

            // Atomically either use PowerShell to query a command info object, or fetch it from the cache
            return(_commandInfoCache.GetOrAdd(key, new Lazy <CommandInfo>(() => GetCommandInfoInternal(commandName, commandTypes))).Value);
        }
        /// <summary>
        /// Retrieve a command info object about a command.
        /// </summary>
        /// <param name="commandName">Name of the command to get a commandinfo object for.</param>
        /// <param name="aliasName">The alias of the command to be used in the cache key. If not given, uses the command name.</param>
        /// <param name="commandTypes">What types of command are needed. If omitted, all types are retrieved.</param>
        /// <returns></returns>
        public CommandInfo GetCommandInfo(string commandName, string aliasName = null, CommandTypes?commandTypes = null)
        {
            if (string.IsNullOrWhiteSpace(commandName))
            {
                return(null);
            }

            // If alias name is given, we store the entry under that, but search with the command name
            var key = new CommandLookupKey(aliasName ?? commandName, commandTypes);

            // Atomically either use PowerShell to query a command info object, or fetch it from the cache
            return(_commandInfoCache.GetOrAdd(key, new Lazy <CommandInfo>(() => GetCommandInfoInternal(commandName, commandTypes))).Value);
        }