/// <summary>
        /// Routine to get the list of loaded snapins...
        /// </summary>
        /// <returns></returns>
        protected internal Collection <PSSnapInInfo> GetSnapIns(string pattern)
        {
            // If RunspaceConfiguration is not null, then return the list that it has
            if (Runspace != null)
            {
                if (pattern != null)
                {
                    return(Runspace.ConsoleInfo.GetPSSnapIn(pattern, _shouldGetAll));
                }
                else
                {
                    return(Runspace.ConsoleInfo.PSSnapIns);
                }
            }

            WildcardPattern matcher = null;

            if (!String.IsNullOrEmpty(pattern))
            {
                bool doWildCardSearch = WildcardPattern.ContainsWildcardCharacters(pattern);

                if (!doWildCardSearch)
                {
                    // Verify PSSnapInID..
                    // This will throw if it not a valid name
                    PSSnapInInfo.VerifyPSSnapInFormatThrowIfError(pattern);
                }
                matcher = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase);
            }

            Collection <PSSnapInInfo> snapins = new Collection <PSSnapInInfo>();

            if (_shouldGetAll)
            {
                foreach (PSSnapInInfo snapinKey in PSSnapInReader.ReadAll())
                {
                    if (matcher == null || matcher.IsMatch(snapinKey.Name))
                    {
                        snapins.Add(snapinKey);
                    }
                }
            }
            else
            {
                // Otherwise, just scan through the list of cmdlets and rebuild the table.
                List <CmdletInfo> cmdlets = InvokeCommand.GetCmdlets();
                Dictionary <PSSnapInInfo, bool> snapinTable = new Dictionary <PSSnapInInfo, bool>();
                foreach (CmdletInfo cmdlet in cmdlets)
                {
                    PSSnapInInfo snapin = cmdlet.PSSnapIn;
                    if (snapin != null && !snapinTable.ContainsKey(snapin))
                    {
                        snapinTable.Add(snapin, true);
                    }
                }

                foreach (PSSnapInInfo snapinKey in snapinTable.Keys)
                {
                    if (matcher == null || matcher.IsMatch(snapinKey.Name))
                    {
                        snapins.Add(snapinKey);
                    }
                }
            }
            return(snapins);
        }