Esempio n. 1
0
        private static Collection <string> GetMatchingPathsInDirectory(
            string pattern,
            string directory)
        {
            Collection <string> collection = new Collection <string>();

            try
            {
                CommandDiscovery.discoveryTracer.WriteLine("Looking for {0} in {1}", (object)pattern, (object)directory);
                collection = SessionStateUtilities.ConvertArrayToCollection <string>(Directory.GetFiles(directory, pattern));
            }
            catch (ArgumentException ex)
            {
                CommandPathSearch.tracer.TraceException((Exception)ex);
                CommandDiscovery.discoveryTracer.TraceException((Exception)ex);
            }
            catch (IOException ex)
            {
                CommandPathSearch.tracer.TraceException((Exception)ex);
                CommandDiscovery.discoveryTracer.TraceException((Exception)ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                CommandPathSearch.tracer.TraceException((Exception)ex);
                CommandDiscovery.discoveryTracer.TraceException((Exception)ex);
            }
            catch (NotSupportedException ex)
            {
                CommandPathSearch.tracer.TraceException((Exception)ex);
                CommandDiscovery.discoveryTracer.TraceException((Exception)ex);
            }
            return(collection);
        }
Esempio n. 2
0
        internal List <PSModuleInfo> GetModules(string[] patterns, bool all)
        {
            if (patterns == null)
            {
                patterns = new string[1] {
                    "*"
                }
            }
            ;
            List <WildcardPattern> wildcardPatternList = new List <WildcardPattern>();

            foreach (string pattern in patterns)
            {
                wildcardPatternList.Add(new WildcardPattern(pattern, WildcardOptions.IgnoreCase));
            }
            List <PSModuleInfo> psModuleInfoList = new List <PSModuleInfo>();

            if (all)
            {
                foreach (string key in this.ModuleTable.Keys)
                {
                    PSModuleInfo psModuleInfo = this.ModuleTable[key];
                    if (SessionStateUtilities.MatchesAnyWildcardPattern(psModuleInfo.Name, (IEnumerable <WildcardPattern>)wildcardPatternList, false))
                    {
                        psModuleInfoList.Add(psModuleInfo);
                    }
                }
            }
            else
            {
                Dictionary <string, bool> dictionary = new Dictionary <string, bool>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);
                foreach (string key in this._context.EngineSessionState.ModuleTable.Keys)
                {
                    PSModuleInfo psModuleInfo = this._context.EngineSessionState.ModuleTable[key];
                    if (SessionStateUtilities.MatchesAnyWildcardPattern(psModuleInfo.Name, (IEnumerable <WildcardPattern>)wildcardPatternList, false))
                    {
                        psModuleInfoList.Add(psModuleInfo);
                        dictionary[key] = true;
                    }
                }
                if (this._context.EngineSessionState != this._context.TopLevelSessionState)
                {
                    foreach (string key in this._context.TopLevelSessionState.ModuleTable.Keys)
                    {
                        if (!dictionary.ContainsKey(key))
                        {
                            PSModuleInfo psModuleInfo = this.ModuleTable[key];
                            if (SessionStateUtilities.MatchesAnyWildcardPattern(psModuleInfo.Name, (IEnumerable <WildcardPattern>)wildcardPatternList, false))
                            {
                                psModuleInfoList.Add(psModuleInfo);
                            }
                        }
                    }
                }
            }
            return(psModuleInfoList);
        }
Esempio n. 3
0
        private static Collection <string> GetMatchingPathsInDirectory(string pattern, string directory, bool allowAnyExtension, HashSet <string> allowedExtensions)
        {
            Collection <string> collection = new Collection <string>();

            try
            {
                CommandDiscovery.discoveryTracer.WriteLine("Looking for {0} in {1}", new object[] { pattern, directory });
                if (!Directory.Exists(directory))
                {
                    return(collection);
                }
                string[] files = null;
                if (!".".Equals(pattern, StringComparison.OrdinalIgnoreCase))
                {
                    files = Directory.GetFiles(directory, pattern);
                }
                List <string> list = null;
                if (files != null)
                {
                    list = new List <string>();
                    if (allowAnyExtension)
                    {
                        list.AddRange(files);
                    }
                    else
                    {
                        foreach (string str in files)
                        {
                            string extension = Path.GetExtension(str);
                            if (!string.IsNullOrEmpty(extension) && allowedExtensions.Contains(extension))
                            {
                                list.Add(str);
                            }
                        }
                    }
                }
                collection = SessionStateUtilities.ConvertListToCollection <string>(list);
            }
            catch (ArgumentException)
            {
            }
            catch (IOException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }
            catch (NotSupportedException)
            {
            }
            return(collection);
        }
Esempio n. 4
0
        internal ScriptAnalysis(string path)
        {
            ModuleIntrinsics.Tracer.WriteLine("Analyzing path: " + path, new object[0]);
            string input = File.ReadAllText(path);

            Token[]       tokens     = null;
            ParseError[]  errors     = null;
            Ast           ast        = Parser.ParseInput(input, out tokens, out errors);
            ExportVisitor astVisitor = new ExportVisitor();

            ast.Visit(astVisitor);
            this.DiscoveredExports        = astVisitor.DiscoveredExports;
            this.DiscoveredAliases        = new Dictionary <string, string>();
            this.DiscoveredModules        = astVisitor.DiscoveredModules;
            this.DiscoveredCommandFilters = astVisitor.DiscoveredCommandFilters;
            if (this.DiscoveredCommandFilters.Count == 0)
            {
                this.DiscoveredCommandFilters.Add("*");
            }
            else
            {
                List <WildcardPattern> patterns = new List <WildcardPattern>();
                foreach (string str2 in this.DiscoveredCommandFilters)
                {
                    patterns.Add(new WildcardPattern(str2));
                }
                foreach (string str3 in astVisitor.DiscoveredAliases.Keys)
                {
                    if (SessionStateUtilities.MatchesAnyWildcardPattern(str3, patterns, false))
                    {
                        this.DiscoveredAliases[str3] = astVisitor.DiscoveredAliases[str3];
                    }
                }
            }
            this.AddsSelfToPath = astVisitor.AddsSelfToPath;
        }
Esempio n. 5
0
        internal static ScriptAnalysis Analyze(string path, ExecutionContext context)
        {
            ModuleIntrinsics.Tracer.WriteLine("Analyzing path: {0}", path);

            try
            {
                if (Utils.PathIsUnc(path) && (context.CurrentCommandProcessor.CommandRuntime != null))
                {
                    ProgressRecord analysisProgress = new ProgressRecord(0,
                                                                         Modules.ScriptAnalysisPreparing,
                                                                         string.Format(CultureInfo.InvariantCulture, Modules.ScriptAnalysisModule, path));
                    analysisProgress.RecordType = ProgressRecordType.Processing;

                    // Write the progress using a static source ID so that all
                    // analysis messages get single-threaded in the progress pane (rather than nesting).
                    context.CurrentCommandProcessor.CommandRuntime.WriteProgress(typeof(ScriptAnalysis).FullName.GetHashCode(), analysisProgress);
                }
            }
            catch (InvalidOperationException)
            {
                // This may be called when we are not allowed to write progress,
                // So eat the invalid operation
            }

            string scriptContent = ReadScript(path);

            ParseError[] errors;
            var          moduleAst = (new Parser()).Parse(path, scriptContent, null, out errors, ParseMode.ModuleAnalysis);

            // Don't bother analyzing if there are syntax errors (we don't do semantic analysis which would
            // detect other errors that we also might choose to ignore, but it's slower.)
            if (errors.Length > 0)
            {
                return(null);
            }

            ExportVisitor exportVisitor = new ExportVisitor(forCompletion: false);

            moduleAst.Visit(exportVisitor);

            var result = new ScriptAnalysis
            {
                DiscoveredClasses        = exportVisitor.DiscoveredClasses,
                DiscoveredExports        = exportVisitor.DiscoveredExports,
                DiscoveredAliases        = new Dictionary <string, string>(),
                DiscoveredModules        = exportVisitor.DiscoveredModules,
                DiscoveredCommandFilters = exportVisitor.DiscoveredCommandFilters,
                AddsSelfToPath           = exportVisitor.AddsSelfToPath
            };

            if (result.DiscoveredCommandFilters.Count == 0)
            {
                result.DiscoveredCommandFilters.Add("*");
            }
            else
            {
                // Post-process aliases, as they are not exported by default
                List <WildcardPattern> patterns = new List <WildcardPattern>();
                foreach (string discoveredCommandFilter in result.DiscoveredCommandFilters)
                {
                    patterns.Add(WildcardPattern.Get(discoveredCommandFilter, WildcardOptions.IgnoreCase));
                }

                foreach (var pair in exportVisitor.DiscoveredAliases)
                {
                    string discoveredAlias = pair.Key;
                    if (SessionStateUtilities.MatchesAnyWildcardPattern(discoveredAlias, patterns, defaultValue: false))
                    {
                        result.DiscoveredAliases[discoveredAlias] = pair.Value;
                    }
                }
            }

            return(result);
        }
Esempio n. 6
0
        private static ConcurrentDictionary <string, CommandTypes> AnalyzeScriptModule(string modulePath, ExecutionContext context, DateTime lastWriteTime)
        {
            var scriptAnalysis = ScriptAnalysis.Analyze(modulePath, context);

            if (scriptAnalysis == null)
            {
                return(null);
            }

            List <WildcardPattern> scriptAnalysisPatterns = new List <WildcardPattern>();

            foreach (string discoveredCommandFilter in scriptAnalysis.DiscoveredCommandFilters)
            {
                scriptAnalysisPatterns.Add(new WildcardPattern(discoveredCommandFilter));
            }

            var result = new ConcurrentDictionary <string, CommandTypes>(3,
                                                                         scriptAnalysis.DiscoveredExports.Count + scriptAnalysis.DiscoveredAliases.Count,
                                                                         StringComparer.OrdinalIgnoreCase);

            // Add any directly discovered exports
            foreach (var command in scriptAnalysis.DiscoveredExports)
            {
                if (SessionStateUtilities.MatchesAnyWildcardPattern(command, scriptAnalysisPatterns, true))
                {
                    if (command.IndexOfAny(InvalidCommandNameCharacters) < 0)
                    {
                        result[command] = CommandTypes.Function;
                    }
                }
            }

            // Add the discovered aliases
            foreach (var pair in scriptAnalysis.DiscoveredAliases)
            {
                var commandName = pair.Key;
                // These are already filtered
                if (commandName.IndexOfAny(InvalidCommandNameCharacters) < 0)
                {
                    result.AddOrUpdate(commandName, CommandTypes.Alias,
                                       (_, existingCommandType) => existingCommandType | CommandTypes.Alias);
                }
            }

            // Add any files in PsScriptRoot if it added itself to the path
            if (scriptAnalysis.AddsSelfToPath)
            {
                string baseDirectory = Path.GetDirectoryName(modulePath);

                try
                {
                    foreach (string item in Directory.GetFiles(baseDirectory, "*.ps1"))
                    {
                        var command = Path.GetFileNameWithoutExtension(item);
                        result.AddOrUpdate(command, CommandTypes.ExternalScript,
                                           (_, existingCommandType) => existingCommandType | CommandTypes.ExternalScript);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    // Consume this exception here
                }
            }

            var exportedClasses = new ConcurrentDictionary <string, TypeAttributes>( /*concurrency*/
                1, scriptAnalysis.DiscoveredClasses.Count, StringComparer.OrdinalIgnoreCase);

            foreach (var exportedClass in scriptAnalysis.DiscoveredClasses)
            {
                exportedClasses[exportedClass.Name] = exportedClass.TypeAttributes;
            }

            var moduleCacheEntry = new ModuleCacheEntry
            {
                ModulePath    = modulePath,
                LastWriteTime = lastWriteTime,
                Commands      = result,
                TypesAnalyzed = true,
                Types         = exportedClasses
            };

            s_cacheData.Entries[modulePath] = moduleCacheEntry;

            return(result);
        }
Esempio n. 7
0
 private bool MatchKeyPattern(IEnumerable <WildcardPattern> patternList, string key)
 {
     return(SessionStateUtilities.MatchesAnyWildcardPattern(key, patternList, true));
 }
Esempio n. 8
0
        private IEnumerable <WildcardPattern> CreateKeyPatternList(string pattern)
        {
            WildcardOptions options = WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase;

            return(SessionStateUtilities.CreateWildcardsFromStrings(new string[] { pattern }, options));
        }
Esempio n. 9
0
 internal static void ExportModuleMembers(
     PSCmdlet cmdlet,
     SessionStateInternal sessionState,
     List <WildcardPattern> functionPatterns,
     List <WildcardPattern> cmdletPatterns,
     List <WildcardPattern> aliasPatterns,
     List <WildcardPattern> variablePatterns)
 {
     sessionState.UseExportList = true;
     if (functionPatterns != null)
     {
         foreach (KeyValuePair <string, FunctionInfo> keyValuePair in (IEnumerable <KeyValuePair <string, FunctionInfo> >)sessionState.ModuleScope.FunctionTable)
         {
             if (SessionStateUtilities.MatchesAnyWildcardPattern(keyValuePair.Key, (IEnumerable <WildcardPattern>)functionPatterns, false))
             {
                 string text = ResourceManagerCache.FormatResourceString("Modules", "ExportingFunction", (object)keyValuePair.Key);
                 cmdlet.WriteVerbose(text);
                 sessionState.ExportedFunctions.Add(keyValuePair.Value);
             }
         }
         ModuleIntrinsics.SortAndRemoveDuplicates <FunctionInfo>(sessionState.ExportedFunctions, (Converter <FunctionInfo, string>)(ci => ci.Name));
     }
     if (cmdletPatterns != null)
     {
         IDictionary <string, List <CmdletInfo> > cmdletCache = (IDictionary <string, List <CmdletInfo> >)sessionState.CmdletCache;
         if (sessionState.Module.CompiledExports.Count > 0)
         {
             CmdletInfo[] array = sessionState.Module.CompiledExports.ToArray();
             sessionState.Module.CompiledExports.Clear();
             foreach (CmdletInfo cmdletInfo1 in array)
             {
                 if (SessionStateUtilities.MatchesAnyWildcardPattern(cmdletInfo1.Name, (IEnumerable <WildcardPattern>)cmdletPatterns, false))
                 {
                     string text = ResourceManagerCache.FormatResourceString("Modules", "ExportingCmdlet", (object)cmdletInfo1.Name);
                     cmdlet.WriteVerbose(text);
                     CmdletInfo cmdletInfo2 = new CmdletInfo(cmdletInfo1.Name, cmdletInfo1.ImplementingType, cmdletInfo1.HelpFile, (PSSnapInInfo)null, cmdletInfo1.Context);
                     cmdletInfo2.SetModule(sessionState.Module);
                     sessionState.Module.CompiledExports.Add(cmdletInfo2);
                 }
             }
         }
         foreach (KeyValuePair <string, List <CmdletInfo> > keyValuePair in (IEnumerable <KeyValuePair <string, List <CmdletInfo> > >)cmdletCache)
         {
             if (SessionStateUtilities.MatchesAnyWildcardPattern(keyValuePair.Key, (IEnumerable <WildcardPattern>)cmdletPatterns, false))
             {
                 string text = ResourceManagerCache.FormatResourceString("Modules", "ExportingCmdlet", (object)keyValuePair.Key);
                 cmdlet.WriteVerbose(text);
                 CmdletInfo cmdletInfo1 = keyValuePair.Value[0];
                 CmdletInfo cmdletInfo2 = new CmdletInfo(cmdletInfo1.Name, cmdletInfo1.ImplementingType, cmdletInfo1.HelpFile, (PSSnapInInfo)null, cmdletInfo1.Context);
                 cmdletInfo2.SetModule(sessionState.Module);
                 sessionState.Module.CompiledExports.Add(cmdletInfo2);
             }
         }
         ModuleIntrinsics.SortAndRemoveDuplicates <CmdletInfo>(sessionState.Module.CompiledExports, (Converter <CmdletInfo, string>)(ci => ci.Name));
     }
     if (variablePatterns != null)
     {
         foreach (KeyValuePair <string, PSVariable> variable in (IEnumerable <KeyValuePair <string, PSVariable> >)sessionState.ModuleScope.Variables)
         {
             if (!variable.Value.IsAllScope && Array.IndexOf <string>(PSModuleInfo.builtinVariables, variable.Key) == -1 && SessionStateUtilities.MatchesAnyWildcardPattern(variable.Key, (IEnumerable <WildcardPattern>)variablePatterns, false))
             {
                 string text = ResourceManagerCache.FormatResourceString("Modules", "ExportingVariable", (object)variable.Key);
                 cmdlet.WriteVerbose(text);
                 sessionState.ExportedVariables.Add(variable.Value);
             }
         }
         ModuleIntrinsics.SortAndRemoveDuplicates <PSVariable>(sessionState.ExportedVariables, (Converter <PSVariable, string>)(v => v.Name));
     }
     if (aliasPatterns == null)
     {
         return;
     }
     foreach (AliasInfo aliasInfo in sessionState.ModuleScope.AliasTable)
     {
         if ((aliasInfo.Options & ScopedItemOptions.AllScope) == ScopedItemOptions.None && SessionStateUtilities.MatchesAnyWildcardPattern(aliasInfo.Name, (IEnumerable <WildcardPattern>)aliasPatterns, false))
         {
             string text = ResourceManagerCache.FormatResourceString("Modules", "ExportingAlias", (object)aliasInfo.Name);
             cmdlet.WriteVerbose(text);
             sessionState.ExportedAliases.Add(aliasInfo);
         }
     }
     ModuleIntrinsics.SortAndRemoveDuplicates <AliasInfo>(sessionState.ExportedAliases, (Converter <AliasInfo, string>)(ci => ci.Name));
 }
Esempio n. 10
0
 internal static Collection <WildcardPattern> CreateWildcardsFromStrings(
     string[] globPatterns,
     WildcardOptions options)
 {
     return(SessionStateUtilities.CreateWildcardsFromStrings(SessionStateUtilities.ConvertArrayToCollection <string>(globPatterns), options));
 }
Esempio n. 11
0
        private List <PSModuleInfo> GetModuleCore(string[] patterns, bool all, bool exactMatch)
        {
            string str = null;
            List <WildcardPattern> list = new List <WildcardPattern>();

            if (exactMatch)
            {
                str = patterns[0];
            }
            else
            {
                if (patterns == null)
                {
                    patterns = new string[] { "*" };
                }
                foreach (string str2 in patterns)
                {
                    list.Add(new WildcardPattern(str2, WildcardOptions.IgnoreCase));
                }
            }
            List <PSModuleInfo> list2 = new List <PSModuleInfo>();

            if (all)
            {
                foreach (string str3 in this.ModuleTable.Keys)
                {
                    PSModuleInfo item = this.ModuleTable[str3];
                    if ((exactMatch && item.Name.Equals(str, StringComparison.OrdinalIgnoreCase)) || (!exactMatch && SessionStateUtilities.MatchesAnyWildcardPattern(item.Name, list, false)))
                    {
                        list2.Add(item);
                    }
                }
            }
            else
            {
                Dictionary <string, bool> dictionary = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);
                foreach (string str4 in this._context.EngineSessionState.ModuleTable.Keys)
                {
                    PSModuleInfo info2 = this._context.EngineSessionState.ModuleTable[str4];
                    if ((exactMatch && info2.Name.Equals(str, StringComparison.OrdinalIgnoreCase)) || (!exactMatch && SessionStateUtilities.MatchesAnyWildcardPattern(info2.Name, list, false)))
                    {
                        list2.Add(info2);
                        dictionary[str4] = true;
                    }
                }
                if (this._context.EngineSessionState != this._context.TopLevelSessionState)
                {
                    foreach (string str5 in this._context.TopLevelSessionState.ModuleTable.Keys)
                    {
                        if (!dictionary.ContainsKey(str5))
                        {
                            PSModuleInfo info3 = this.ModuleTable[str5];
                            if ((exactMatch && info3.Name.Equals(str, StringComparison.OrdinalIgnoreCase)) || (!exactMatch && SessionStateUtilities.MatchesAnyWildcardPattern(info3.Name, list, false)))
                            {
                                list2.Add(info3);
                            }
                        }
                    }
                }
            }
            return((from m in list2
                    orderby m.Name
                    select m).ToList <PSModuleInfo>());
        }
Esempio n. 12
0
 internal static void ExportModuleMembers(PSCmdlet cmdlet, SessionStateInternal sessionState, List <WildcardPattern> functionPatterns, List <WildcardPattern> cmdletPatterns, List <WildcardPattern> aliasPatterns, List <WildcardPattern> variablePatterns, List <string> doNotExportCmdlets)
 {
     sessionState.UseExportList = true;
     if (functionPatterns != null)
     {
         foreach (KeyValuePair <string, FunctionInfo> pair in sessionState.ModuleScope.FunctionTable)
         {
             if (((pair.Value.Options & ScopedItemOptions.AllScope) == ScopedItemOptions.None) && SessionStateUtilities.MatchesAnyWildcardPattern(pair.Key, functionPatterns, false))
             {
                 string str;
                 if (pair.Value.CommandType == CommandTypes.Workflow)
                 {
                     str = StringUtil.Format(Modules.ExportingWorkflow, pair.Key);
                     sessionState.ExportedWorkflows.Add((WorkflowInfo)pair.Value);
                 }
                 else
                 {
                     str = StringUtil.Format(Modules.ExportingFunction, pair.Key);
                     sessionState.ExportedFunctions.Add(pair.Value);
                 }
                 cmdlet.WriteVerbose(str);
             }
         }
         SortAndRemoveDuplicates <FunctionInfo>(sessionState.ExportedFunctions, ci => ci.Name);
         SortAndRemoveDuplicates <WorkflowInfo>(sessionState.ExportedWorkflows, ci => ci.Name);
     }
     if (cmdletPatterns != null)
     {
         IDictionary <string, List <CmdletInfo> > cmdletTable = sessionState.ModuleScope.CmdletTable;
         if (sessionState.Module.CompiledExports.Count > 0)
         {
             CmdletInfo[] infoArray = sessionState.Module.CompiledExports.ToArray();
             sessionState.Module.CompiledExports.Clear();
             CmdletInfo[] infoArray2 = infoArray;
             for (int i = 0; i < infoArray2.Length; i++)
             {
                 Predicate <string> match   = null;
                 CmdletInfo         element = infoArray2[i];
                 if (doNotExportCmdlets != null)
                 {
                     if (match == null)
                     {
                         match = cmdletName => string.Equals(element.FullName, cmdletName, StringComparison.OrdinalIgnoreCase);
                     }
                     if (doNotExportCmdlets.Exists(match))
                     {
                         continue;
                     }
                 }
                 if (SessionStateUtilities.MatchesAnyWildcardPattern(element.Name, cmdletPatterns, false))
                 {
                     string text = StringUtil.Format(Modules.ExportingCmdlet, element.Name);
                     cmdlet.WriteVerbose(text);
                     CmdletInfo item = new CmdletInfo(element.Name, element.ImplementingType, element.HelpFile, null, element.Context);
                     item.SetModule(sessionState.Module);
                     sessionState.Module.CompiledExports.Add(item);
                 }
             }
         }
         foreach (KeyValuePair <string, List <CmdletInfo> > pair2 in cmdletTable)
         {
             CmdletInfo cmdletToImport = pair2.Value[0];
             if (((doNotExportCmdlets == null) || !doNotExportCmdlets.Exists(cmdletName => string.Equals(cmdletToImport.FullName, cmdletName, StringComparison.OrdinalIgnoreCase))) && SessionStateUtilities.MatchesAnyWildcardPattern(pair2.Key, cmdletPatterns, false))
             {
                 string str3 = StringUtil.Format(Modules.ExportingCmdlet, pair2.Key);
                 cmdlet.WriteVerbose(str3);
                 CmdletInfo info2 = new CmdletInfo(cmdletToImport.Name, cmdletToImport.ImplementingType, cmdletToImport.HelpFile, null, cmdletToImport.Context);
                 info2.SetModule(sessionState.Module);
                 sessionState.Module.CompiledExports.Add(info2);
             }
         }
         SortAndRemoveDuplicates <CmdletInfo>(sessionState.Module.CompiledExports, ci => ci.Name);
     }
     if (variablePatterns != null)
     {
         foreach (KeyValuePair <string, PSVariable> pair3 in sessionState.ModuleScope.Variables)
         {
             if ((!pair3.Value.IsAllScope && (Array.IndexOf <string>(PSModuleInfo._builtinVariables, pair3.Key) == -1)) && SessionStateUtilities.MatchesAnyWildcardPattern(pair3.Key, variablePatterns, false))
             {
                 string str4 = StringUtil.Format(Modules.ExportingVariable, pair3.Key);
                 cmdlet.WriteVerbose(str4);
                 sessionState.ExportedVariables.Add(pair3.Value);
             }
         }
         SortAndRemoveDuplicates <PSVariable>(sessionState.ExportedVariables, v => v.Name);
     }
     if (aliasPatterns != null)
     {
         foreach (AliasInfo info3 in sessionState.ModuleScope.AliasTable)
         {
             if (((info3.Options & ScopedItemOptions.AllScope) == ScopedItemOptions.None) && SessionStateUtilities.MatchesAnyWildcardPattern(info3.Name, aliasPatterns, false))
             {
                 string str5 = StringUtil.Format(Modules.ExportingAlias, info3.Name);
                 cmdlet.WriteVerbose(str5);
                 sessionState.ExportedAliases.Add(info3);
             }
         }
         SortAndRemoveDuplicates <AliasInfo>(sessionState.ExportedAliases, ci => ci.Name);
     }
 }