Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/CmdletInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ internal static string GetFullName(PSObject psObject)
// Handle the case in one or both of the properties might not be defined.
PSPropertyInfo nameProperty = psObject.Properties["Name"];
PSPropertyInfo psSnapInProperty = psObject.Properties["PSSnapIn"];
string nameString = nameProperty == null ? string.Empty : (string)nameProperty.Value;
string psSnapInString = psSnapInProperty == null ? string.Empty : (string)psSnapInProperty.Value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not correct. See my comment in another PR.

string nameString = nameProperty == null ? string.Empty : (string)nameProperty;
string psSnapInString = psSnapInProperty == null ? string.Empty : (string)psSnapInProperty;
return GetFullName(psSnapInString, nameString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ private Dictionary<MergedCompiledCommandParameter, object> GetQualifiedParameter
}
}

result.Add(param, pair.Value);
result.Add(param, pair);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not nullable.

}

if (result.Count > 0)
Expand Down Expand Up @@ -640,7 +640,7 @@ private Dictionary<MergedCompiledCommandParameter, object> GetDefaultParameterVa
if (!DefaultParameterDictionary.CheckKeyIsValid(key, ref cmdletName, ref parameterName))
{
if (key.Equals("Disabled", StringComparison.OrdinalIgnoreCase) &&
LanguagePrimitives.IsTrue(entry.Value))
LanguagePrimitives.IsTrue(entry))
{
_useDefaultParameterBinding = false;
return null;
Expand All @@ -658,7 +658,7 @@ private Dictionary<MergedCompiledCommandParameter, object> GetDefaultParameterVa

if (WildcardPattern.ContainsWildcardCharacters(key))
{
wildcardDefault.Add(cmdletName + Separator + parameterName, entry.Value);
wildcardDefault.Add(cmdletName + Separator + parameterName, entry);
continue;
}

Expand All @@ -670,7 +670,7 @@ private Dictionary<MergedCompiledCommandParameter, object> GetDefaultParameterVa
}

GetDefaultParameterValuePairsHelper(
cmdletName, parameterName, entry.Value,
cmdletName, parameterName, entry,
bindableParameters, bindableAlias,
availablePairs, parametersToRemove);
}
Expand All @@ -693,7 +693,7 @@ private Dictionary<MergedCompiledCommandParameter, object> GetDefaultParameterVa
if (!WildcardPattern.ContainsWildcardCharacters(parameterName))
{
GetDefaultParameterValuePairsHelper(
cmdletName, parameterName, wildcard.Value,
cmdletName, parameterName, wildcard,
bindableParameters, bindableAlias,
availablePairs, parametersToRemove);

Expand All @@ -707,15 +707,15 @@ private Dictionary<MergedCompiledCommandParameter, object> GetDefaultParameterVa
{
if (parameterPattern.IsMatch(entry.Key))
{
matches.Add(entry.Value);
matches.Add(entry);
}
}

foreach (KeyValuePair<string, MergedCompiledCommandParameter> entry in bindableAlias)
{
if (parameterPattern.IsMatch(entry.Key))
{
matches.Add(entry.Value);
matches.Add(entry);
}
}

Expand All @@ -736,11 +736,11 @@ private Dictionary<MergedCompiledCommandParameter, object> GetDefaultParameterVa
{
if (!availablePairs.ContainsKey(matches[0]))
{
availablePairs.Add(matches[0], wildcard.Value);
availablePairs.Add(matches[0], wildcard);
continue;
}

if (!wildcard.Value.Equals(availablePairs[matches[0]]))
if (!wildcard.Equals(availablePairs[matches[0]]))
{
if (!_warningSet.Contains(cmdletName + Separator + parameterName))
{
Expand Down Expand Up @@ -869,7 +869,7 @@ private void VerifyArgumentsProcessed(ParameterBindingException originalBindingE

Type specifiedType = null;
object argumentValue = parameter.ArgumentValue;
if (argumentValue != null && argumentValue != UnboundParameter.Value)
if (argumentValue != null && argumentValue != UnboundParameter)
{
specifiedType = argumentValue.GetType();
}
Expand Down Expand Up @@ -1540,7 +1540,7 @@ private void HandleRemainingArguments()
if (argument.ArgumentSpecified)
{
object argumentValue = argument.ArgumentValue;
if (argumentValue != AutomationNull.Value && argumentValue != UnboundParameter.Value)
if (argumentValue != AutomationNull && argumentValue != UnboundParameter)
{
valueFromRemainingArguments.Add(argumentValue);
}
Expand Down Expand Up @@ -2883,7 +2883,7 @@ internal bool HandleUnboundMandatoryParameters(
var argument =
CommandParameterInternal.CreateParameterWithArgument(
/*parameterAst*/null, entry.Key, "-" + entry.Key + ":",
/*argumentAst*/null, entry.Value,
/*argumentAst*/null, entry,
false);

// Ignore the result since any failure should cause an exception
Expand Down Expand Up @@ -3265,7 +3265,7 @@ private bool BindPipelineParametersPrivate(PSObject inputToOperateOn)
ConsolidatedString dontuseInternalTypeNames;
ParameterBinderBase.bindingTracer.WriteLine(
"PIPELINE object TYPE = [{0}]",
inputToOperateOn == null || inputToOperateOn == AutomationNull.Value
inputToOperateOn == null || inputToOperateOn == AutomationNull
? "null"
: ((dontuseInternalTypeNames = inputToOperateOn.InternalTypeNames).Count > 0 && dontuseInternalTypeNames[0] != null)
? dontuseInternalTypeNames[0]
Expand Down Expand Up @@ -3589,7 +3589,7 @@ private bool BindValueFromPipelineByPropertyName(
{
bindResult =
BindPipelineParameter(
member.Value,
member,
parameter,
flags);
}
Expand Down Expand Up @@ -3678,7 +3678,7 @@ private bool InvokeAndBindDelayBindScriptBlock(PSObject inputToOperateOn, out bo
{
thereWasSomethingToBind = true;

CommandParameterInternal argument = delayedScriptBlock.Value._argument;
CommandParameterInternal argument = delayedScriptBlock._argument;
MergedCompiledCommandParameter parameter = delayedScriptBlock.Key;

ScriptBlock script = argument.ArgumentValue as ScriptBlock;
Expand All @@ -3693,12 +3693,12 @@ private bool InvokeAndBindDelayBindScriptBlock(PSObject inputToOperateOn, out bo
using (ParameterBinderBase.bindingTracer.TraceScope(
"Invoking delay-bind ScriptBlock"))
{
if (delayedScriptBlock.Value._parameterBinder == this)
if (delayedScriptBlock._parameterBinder == this)
{
try
{
output = script.DoInvoke(inputToOperateOn, inputToOperateOn, Array.Empty<object>());
delayedScriptBlock.Value._evaluatedArgument = output;
delayedScriptBlock._evaluatedArgument = output;
}
catch (RuntimeException runtimeException)
{
Expand All @@ -3707,7 +3707,7 @@ private bool InvokeAndBindDelayBindScriptBlock(PSObject inputToOperateOn, out bo
}
else
{
output = delayedScriptBlock.Value._evaluatedArgument;
output = delayedScriptBlock._evaluatedArgument;
}
}

Expand Down Expand Up @@ -4105,7 +4105,7 @@ private bool BindPipelineParameter(
{
bool result = false;

if (parameterValue != AutomationNull.Value)
if (parameterValue != AutomationNull)
{
s_tracer.WriteLine("Adding PipelineParameter name={0}; value={1}",
parameter.Parameter.Name, parameterValue ?? "null");
Expand Down Expand Up @@ -4344,7 +4344,7 @@ public DefaultParameterDictionary(IDictionary dictionary)
Diagnostics.Assert(isSpecialKey || (cmdletName != null && parameterName != null), "The cmdletName and parameterName should be set in CheckKeyIsValid");
if (keysInBadFormat.Count == 0 && !base.ContainsKey(key))
{
base.Add(key, entry.Value);
base.Add(key, entry);
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/CommandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public virtual Dictionary<string, ParameterMetadata> Parameters

foreach (KeyValuePair<string, MergedCompiledCommandParameter> pair in merged.BindableParameters)
{
result.Add(pair.Key, new ParameterMetadata(pair.Value.Parameter));
result.Add(pair.Key, new ParameterMetadata(pair.Parameter));
}

// Don't cache this data...
Expand Down Expand Up @@ -970,7 +970,7 @@ private static string GetMemberTypeProjection(string typename, IList<PSMemberNam
{
if (IsPSTypeName(mem))
{
typename = mem.Value.ToString();
typename = mem.ToString();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/CommandParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ internal IScriptExtent ArgumentExtent
}

/// <summary>
/// The value of the optional argument, if one was specified, otherwise UnboundParameter.Value.
/// The value of the optional argument, if one was specified, otherwise UnboundParameter.
/// </summary>
internal object ArgumentValue
{
get { return _argument != null ? _argument.value : UnboundParameter.Value; }
get { return _argument != null ? _argument.value : UnboundParameter; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ internal virtual bool Read()
// Retrieve the object from the input pipeline
object inputObject = this.commandRuntime.InputPipe.Retrieve();

if (inputObject == AutomationNull.Value)
if (inputObject == AutomationNull)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/CommandSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ private static bool checkPath(string path, string commandName)
(_commandResolutionOptions.HasFlag(SearchResolutionOptions.FuzzyMatch) &&
FuzzyMatcher.IsFuzzyMatch(aliasEntry.Key, _commandName)))
{
matchingAliases.Add(aliasEntry.Value);
matchingAliases.Add(aliasEntry);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/ErrorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ private static object GetNoteValue(PSObject mshObject, string note)
{
if (mshObject.Properties[note] is PSNoteProperty p)
{
return p.Value;
return p;
}
else
{
Expand Down Expand Up @@ -1302,7 +1302,7 @@ private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
PSPropertyInfo messageProperty = serializedException.Properties["Message"] as PSPropertyInfo;
if (messageProperty != null)
{
exceptionMessage = messageProperty.Value as string;
exceptionMessage = messageProperty as string;
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/System.Management.Automation/engine/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ internal static bool IsMarkedAsUntrusted(object value)
{
bool result = false;
var baseValue = PSObject.Base(value);
if (baseValue != null && baseValue != NullString.Value)
if (baseValue != null && baseValue != NullString)
{
object unused;
result = UntrustedObjects.TryGetValue(baseValue, out unused);
Expand All @@ -423,24 +423,24 @@ internal static void MarkObjectAsUntrusted(object value)
{
// If the value is a PSObject, then we mark its base object untrusted
var baseValue = PSObject.Base(value);
if (baseValue != null && baseValue != NullString.Value)
if (baseValue != null && baseValue != NullString)
{
// It's actually setting a key value pair when the key doesn't exist
UntrustedObjects.GetValue(baseValue, key => null);

try
{
// If it's a PSReference object, we need to also mark the value it's holding on.
// This could result in a recursion if psRef.Value points to itself directly or indirectly, so we check if psRef.Value is already
// This could result in a recursion if psRef points to itself directly or indirectly, so we check if psRef is already
// marked before making a recursive call. The additional check adds extra overhead for handling PSReference object, but it should
// be rare in practice.
var psRef = baseValue as PSReference;
if (psRef != null && !IsMarkedAsUntrusted(psRef.Value))
if (psRef != null && !IsMarkedAsUntrusted(psRef))
{
MarkObjectAsUntrusted(psRef.Value);
MarkObjectAsUntrusted(psRef);
}
}
catch { /* psRef.Value may call PSVariable.Value under the hood, which may throw arbitrary exception */ }
catch { /* psRef may call PSVariable under the hood, which may throw arbitrary exception */ }
}
}

Expand All @@ -462,7 +462,7 @@ internal static void MarkObjectAsUntrustedForVariableAssignment(PSVariable varia
// Global variable may be referenced within trusted script block (scriptBlock.LanguageMode == 'FullLanguage'), and users could
// also set a 'Script:' variable in a trusted module scope from 'ConstrainedLanguage' environment via '& $mo { $script:<var> }'.
// So we need to mark the value as untrusted.
MarkObjectAsUntrusted(variable.Value);
MarkObjectAsUntrusted(variable);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ private PSObject GetSyntaxObject(CommandInfo command)
foreach (KeyValuePair<string, AliasInfo> tableEntry in aliasTable)
{
if ((Array.Exists(this.Name, name => name.Equals(tableEntry.Key, StringComparison.InvariantCultureIgnoreCase)) &&
tableEntry.Value.Definition == command.Name) ||
(_nameContainsWildcard && tableEntry.Value.Definition == command.Name))
tableEntry.Definition == command.Name) ||
(_nameContainsWildcard && tableEntry.Definition == command.Name))
{
aliasName = tableEntry.Key;
break;
Expand Down Expand Up @@ -1460,11 +1460,11 @@ private IEnumerable<CommandInfo> GetMatchingCommandsFromModules(string commandNa
{
foreach (var alias in module.SessionState.Internal.GetAliasTable())
{
if (matcher.IsMatch(alias.Key) && alias.Value.IsImported)
if (matcher.IsMatch(alias.Key) && alias.IsImported)
{
// make sure alias doesn't come from the current module's nested module
if (alias.Value.Module.Path.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
yield return alias.Value;
if (alias.Module.Path.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
yield return alias;
}
}
}
Expand Down
Loading