GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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.

Sign up for GitHub

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

Merged
Ilya (iSazonov) merged 3 commits into PowerShell:master from iSazonov:Use-nameof()-in-BoundParameters.ContainsKey()
Oct 2, 2018

Uh oh!

There was an error while loading. Please reload this page.

Merged

Use nameof() in bound parameters.contains key() #7908

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
afeca41
Step 1
iSazonov Oct 1, 2018
9911938
Step 2
iSazonov Oct 1, 2018
fce2d87
[Feature] Step 3
iSazonov Oct 1, 2018
File filter
Filter by extension

Clear filters
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
Diff view

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 src/Microsoft.PowerShell.Commands.Utility/commands/utility/CSVCommands.cs
Show comments
View file
Open in desktop
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
2 changes: 1 addition & 1 deletion 2 ...crosoft.PowerShell.Commands.Utility/commands/utility/EnableDisableRunspaceDebugCommand.cs
Show comments
View file
Open in desktop
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
12 changes: 6 additions & 6 deletions 12 src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs
Show comments
View file
Open in desktop
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
12 changes: 6 additions & 6 deletions 12 src/Microsoft.PowerShell.ScheduledJob/commands/NewJobTrigger.cs
Show comments
View file
Open in desktop
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
4 changes: 2 additions & 2 deletions 4 src/Microsoft.PowerShell.ScheduledJob/commands/RegisterJobDefinition.cs
Show comments
View file
Open in desktop
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
4 changes: 2 additions & 2 deletions 4 src/Microsoft.PowerShell.ScheduledJob/commands/ScheduledJobOptionCmdletBase.cs
Show comments
View file
Open in desktop
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
8 changes: 4 additions & 4 deletions 8 src/Microsoft.PowerShell.ScheduledJob/commands/SetJobDefinition.cs
Show comments
View file
Open in desktop
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.