Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/System.Management.Automation/engine/CommandSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,19 +778,19 @@ private CommandInfo GetNextFunction()
_commandName,
WildcardOptions.IgnoreCase);

foreach (DictionaryEntry functionEntry in _context.EngineSessionState.GetFunctionTable())
foreach ((string functionName, FunctionInfo functionInfo) in _context.EngineSessionState.GetFunctionTable())
{
if (functionMatcher.IsMatch((string)functionEntry.Key) ||
if (functionMatcher.IsMatch(functionName) ||
(_commandResolutionOptions.HasFlag(SearchResolutionOptions.FuzzyMatch) &&
FuzzyMatcher.IsFuzzyMatch(functionEntry.Key.ToString(), _commandName)))
FuzzyMatcher.IsFuzzyMatch(functionName, _commandName)))
{
matchingFunction.Add((CommandInfo)functionEntry.Value);
matchingFunction.Add(functionInfo);
}
else if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.UseAbbreviationExpansion))
{
if (_commandName.Equals(ModuleUtils.AbbreviateName((string)functionEntry.Key), StringComparison.OrdinalIgnoreCase))
if (_commandName.Equals(ModuleUtils.AbbreviateName(functionName), StringComparison.OrdinalIgnoreCase))
{
matchingFunction.Add((CommandInfo)functionEntry.Value);
matchingFunction.Add(functionInfo);
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,12 @@ private PSObject GetSyntaxObject(CommandInfo command)
if (this.Name != null && !Array.Exists(this.Name, name => name.Equals(command.Name, StringComparison.InvariantCultureIgnoreCase)))
{
string aliasName = _nameContainsWildcard ? command.Name : this.Name[0];

IDictionary<string, AliasInfo> aliasTable = SessionState.Internal.GetAliasTable();
foreach (KeyValuePair<string, AliasInfo> tableEntry in aliasTable)
{
if ((Array.Exists(this.Name, name => name.Equals(tableEntry.Key, StringComparison.InvariantCultureIgnoreCase)) &&
tableEntry.Value.Definition == command.Name) ||
if ((Array.Exists(this.Name, name => name.Equals(tableEntry.Key, StringComparison.InvariantCultureIgnoreCase)) &&
tableEntry.Value.Definition == command.Name) ||
(_nameContainsWildcard && tableEntry.Value.Definition == command.Name))
{
aliasName = tableEntry.Key;
Expand Down Expand Up @@ -635,7 +635,7 @@ private PSObject GetSyntaxObject(CommandInfo command)

break;
}

syntax = PSObject.AsPSObject(replacedSyntax);
}

Expand Down Expand Up @@ -1444,15 +1444,13 @@ private IEnumerable<CommandInfo> GetMatchingCommandsFromModules(string commandNa
// Look in function table
if ((this.CommandType & (CommandTypes.Function | CommandTypes.Filter | CommandTypes.Configuration)) != 0)
{
foreach (DictionaryEntry function in module.SessionState.Internal.GetFunctionTable())
foreach ((string functionName, FunctionInfo functionInfo) in module.SessionState.Internal.GetFunctionTable())
{
FunctionInfo func = (FunctionInfo)function.Value;

if (matcher.IsMatch((string)function.Key) && func.IsImported)
if (matcher.IsMatch(functionName) && functionInfo.IsImported)
{
// make sure function doesn't come from the current module's nested module
if (func.Module.Path.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
yield return (CommandInfo)function.Value;
if (functionInfo.Module.Path.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
yield return functionInfo;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5074,29 +5074,29 @@ internal void RemoveModule(PSModuleInfo module, string moduleNameInRemoveModuleC
// Remove the imported functions from SessionState...
// (can't just go through module.SessionState.Internal.ExportedFunctions,
// because the names of the functions might have been changed by the -Prefix parameter of Import-Module)
foreach (DictionaryEntry entry in ss.GetFunctionTable())
foreach ((var _, FunctionInfo functionInfo) in ss.GetFunctionTable())
{
FunctionInfo func = (FunctionInfo)entry.Value;
if (func.Module == null)
if (functionInfo.Module == null)
{
continue;
}

if (func.Module.Path.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
if (functionInfo.Module.Path.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
{
string functionName = functionInfo.Name;
try
{
ss.RemoveFunction(func.Name, true);
ss.RemoveFunction(functionName, true);

string memberMessage = StringUtil.Format(Modules.RemovingImportedFunction, func.Name);
string memberMessage = StringUtil.Format(Modules.RemovingImportedFunction, functionName);
WriteVerbose(memberMessage);
}
catch (SessionStateUnauthorizedAccessException e)
{
string message = StringUtil.Format(Modules.UnableToRemoveModuleMember, func.Name, module.Name, e.Message);
string message = StringUtil.Format(Modules.UnableToRemoveModuleMember, functionName, module.Name, e.Message);
InvalidOperationException memberNotRemoved = new InvalidOperationException(message, e);
ErrorRecord er = new ErrorRecord(memberNotRemoved, "Modules_MemberNotRemoved",
ErrorCategory.PermissionDenied, func.Name);
ErrorCategory.PermissionDenied, functionName);
WriteError(er);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal void AddSessionStateEntry(SessionStateFunctionEntry entry)
/// <returns>
/// An IDictionary representing the visible functions.
/// </returns>
internal IDictionary GetFunctionTable()
internal IDictionary<string, FunctionInfo> GetFunctionTable()
{
SessionStateScopeEnumerator scopeEnumerator =
new SessionStateScopeEnumerator(_currentScope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ internal override object GetValueOfItem(object item)
/// </returns>
internal override IDictionary GetSessionStateTable()
{
return SessionState.Internal.GetFunctionTable();
return (IDictionary)SessionState.Internal.GetFunctionTable();
Comment thread
powercode marked this conversation as resolved.
}

/// <summary>
Expand Down