GeezerVison is showing github.com — Use nameof() in bound parameters.contains key() by iSazonov · Pull Request #7908 · PowerShell/PowerShell
Use nameof() in bound parameters.contains key()
#7908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.cs
(11)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -98,7 +98,7 @@ protected override void BeginProcessing()
ErrorRecord errorRecord = new ErrorRecord(exception, "CannotSpecifyIncludeTypeInformationAndNoTypeInformation", ErrorCategory.InvalidData, null);
this.ThrowTerminatingError(errorRecord);
}
if (this.MyInvocation.BoundParameters.ContainsKey(" IncludeTypeInformation" ))
if (this.MyInvocation.BoundParameters.ContainsKey(nameof( IncludeTypeInformation) ))
{
NoTypeInformation = !IncludeTypeInformation;
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -389,7 +389,7 @@ protected override void ProcessRecord()
// Enable debugging by preserving debug stop events.
debugger.UnhandledBreakpointMode = UnhandledBreakpointProcessingMode.Wait;
if (this.MyInvocation.BoundParameters.ContainsKey(" BreakAll" ))
if (this.MyInvocation.BoundParameters.ContainsKey(nameof( BreakAll) ))
{
if (BreakAll)
{
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -115,7 +115,7 @@ protected override void BeginProcessing()
// Throw out terminating error if this is the case.
if (IsModuleSpecified && IsFullyQualifiedModuleSpecified)
{
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, " Module", " FullyQualifiedModule" );
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, nameof( Module), nameof( FullyQualifiedModule) );
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "ModuleAndFullyQualifiedModuleCannotBeSpecifiedTogether", ErrorCategory.InvalidOperation, null);
ThrowTerminatingError(error);
}
Expand Down
Expand Up
@@ -275,7 +275,7 @@ protected override void BeginProcessing()
// Throw out terminating error if this is the case.
if (IsModuleSpecified && IsFullyQualifiedModuleSpecified)
{
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, " Module", " FullyQualifiedModule" );
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, nameof( Module), nameof( FullyQualifiedModule) );
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "ModuleAndFullyQualifiedModuleCannotBeSpecifiedTogether", ErrorCategory.InvalidOperation, null);
ThrowTerminatingError(error);
}
Expand Down
Expand Up
@@ -1643,10 +1643,10 @@ private PowerShell BuildPowerShellForGetCommand()
{
powerShell.AddParameter("Name", this.CommandName);
}
powerShell.AddParameter(" Module" , this.Module);
powerShell.AddParameter(nameof( Module) , this.Module);
if (IsFullyQualifiedModuleSpecified)
{
powerShell.AddParameter(" FullyQualifiedModule" , this.FullyQualifiedModule);
powerShell.AddParameter(nameof( FullyQualifiedModule) , this.FullyQualifiedModule);
}
powerShell.AddParameter("ArgumentList", this.ArgumentList);
Expand Down
Expand Up
@@ -2405,9 +2405,9 @@ private string GenerateReimportingOfModules()
{
StringBuilder result = new StringBuilder();
if (_invocationInfo.BoundParameters.ContainsKey(" Module" ))
if (_invocationInfo.BoundParameters.ContainsKey(nameof( Module) ))
{
string[] moduleNames = (string[])_invocationInfo.BoundParameters[" Module" ];
string[] moduleNames = (string[])_invocationInfo.BoundParameters[nameof( Module) ];
foreach (string moduleName in moduleNames)
{
result.AppendFormat(
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -272,22 +272,22 @@ private void CreateOnceTrigger()
{
TimeSpan? repInterval = null;
TimeSpan? repDuration = null;
if (MyInvocation.BoundParameters.ContainsKey(" RepetitionInterval") || MyInvocation.BoundParameters.ContainsKey(" RepetitionDuration" ) ||
MyInvocation.BoundParameters.ContainsKey(" RepeatIndefinitely" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( RepetitionInterval)) || MyInvocation.BoundParameters.ContainsKey(nameof( RepetitionDuration) ) ||
MyInvocation.BoundParameters.ContainsKey(nameof( RepeatIndefinitely) ))
{
if (MyInvocation.BoundParameters.ContainsKey(" RepeatIndefinitely" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( RepeatIndefinitely) ))
{
if (MyInvocation.BoundParameters.ContainsKey(" RepetitionDuration" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( RepetitionDuration) ))
{
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidRepeatIndefinitelyParams);
}
if (!MyInvocation.BoundParameters.ContainsKey(" RepetitionInterval" ))
if (!MyInvocation.BoundParameters.ContainsKey(nameof( RepetitionInterval) ))
{
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidRepetitionRepeatParams);
}
_repDuration = TimeSpan.MaxValue;
}
else if (!MyInvocation.BoundParameters.ContainsKey(" RepetitionInterval") || !MyInvocation.BoundParameters.ContainsKey(" RepetitionDuration" ))
else if (!MyInvocation.BoundParameters.ContainsKey(nameof( RepetitionInterval)) || !MyInvocation.BoundParameters.ContainsKey(nameof( RepetitionDuration) ))
{
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidRepetitionParams);
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -227,7 +227,7 @@ protected override void ProcessRecord()
if (definition != null)
{
// Set the MaxCount value if available.
if (MyInvocation.BoundParameters.ContainsKey(" MaxResultCount" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( MaxResultCount) ))
{
if (MaxResultCount < 1)
{
Expand All
@@ -245,7 +245,7 @@ protected override void ProcessRecord()
{
// If RunEvery parameter is specified then create a job trigger for the definition that
// runs the job at the requested interval.
if (MyInvocation.BoundParameters.ContainsKey(" RunEvery" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( RunEvery) ))
{
AddRepetitionJobTriggerToDefinition(
definition,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -175,13 +175,13 @@ public SwitchParameter StartIfIdle
protected override void BeginProcessing()
{
// Validate parameters.
if (MyInvocation.BoundParameters.ContainsKey(" IdleTimeout" ) &&
if (MyInvocation.BoundParameters.ContainsKey(nameof( IdleTimeout) ) &&
_idleTimeout < TimeSpan.Zero)
{
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidIdleTimeout);
}
if (MyInvocation.BoundParameters.ContainsKey(" IdleDuration" ) &&
if (MyInvocation.BoundParameters.ContainsKey(nameof( IdleDuration) ) &&
_idleDuration < TimeSpan.Zero)
{
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidIdleDuration);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -258,7 +258,7 @@ protected override void ProcessRecord()
// If RunEvery parameter is specified then create a job trigger for the definition that
// runs the job at the requested interval.
bool addedTrigger = false;
if (MyInvocation.BoundParameters.ContainsKey(" RunEvery" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( RunEvery) ))
{
AddRepetitionJobTriggerToDefinition(
_definition,
Expand Down
Expand Up
@@ -340,7 +340,7 @@ private void UpdateDefinition()
UpdateJobInvocationInfo();
if (MyInvocation.BoundParameters.ContainsKey(" MaxResultCount" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( MaxResultCount) ))
{
_definition.SetExecutionHistoryLength(MaxResultCount, false);
}
Expand Down
Expand Up
@@ -406,7 +406,7 @@ private Dictionary<string, object> UpdateParameters()
}
// RunAs32
if (MyInvocation.BoundParameters.ContainsKey(" RunAs32" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( RunAs32) ))
{
if (newParameters.ContainsKey(ScheduledJobInvocationInfo.RunAs32Parameter))
{
Expand All
@@ -419,7 +419,7 @@ private Dictionary<string, object> UpdateParameters()
}
// Authentication
if (MyInvocation.BoundParameters.ContainsKey(" Authentication" ))
if (MyInvocation.BoundParameters.ContainsKey(nameof( Authentication) ))
{
if (newParameters.ContainsKey(ScheduledJobInvocationInfo.AuthenticationParameter))
{
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.