internal static CmdletInfo NewCmdletInfo( SessionStateCmdletEntry entry, ExecutionContext context) { CmdletInfo cmdletInfo = new CmdletInfo(entry.Name, entry.ImplementingType, entry.HelpFileName, entry.PSSnapIn, context); cmdletInfo.Visibility = entry.Visibility; cmdletInfo.SetModule(entry.Module); return(cmdletInfo); }
internal static CmdletInfo NewCmdletInfo(SessionStateCmdletEntry entry, ExecutionContext context) { CmdletInfo info = new CmdletInfo(entry.Name, entry.ImplementingType, entry.HelpFileName, entry.PSSnapIn, context) { Visibility = entry.Visibility }; info.SetModule(entry.Module); return info; }
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)); }
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); } }