From d45170e82b18ad7ca161c8dd3bb6216945719e89 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 5 Oct 2025 18:34:20 +0100 Subject: [PATCH 1/3] `IsPresent` -> operator --- .../CimSessionOperations.cs | 2 +- .../CimSessionProxy.cs | 4 +-- .../ExportCounterCommand.cs | 4 +-- .../GetCounterCommand.cs | 4 +-- .../GetEventCommand.cs | 12 ++++---- .../cmdletization/SessionBasedWrapper.cs | 26 ++++++++--------- .../commands/management/Computer.cs | 2 +- .../management/GetWMIObjectCommand.cs | 6 ++-- .../commands/management/Process.cs | 12 ++++---- .../commands/management/Service.cs | 8 +++--- .../management/TestConnectionCommand.cs | 28 +++++++++---------- .../commands/management/TimeZoneCommands.cs | 4 +-- .../commands/management/WMIHelper.cs | 4 +-- .../commands/management/WebServiceProxy.cs | 4 +-- .../commands/utility/AddType.cs | 4 +-- .../commands/utility/CsvCommands.cs | 4 +-- .../OutGridView/OutGridViewCommand.cs | 2 +- .../commands/utility/GetUnique.cs | 4 +-- .../commands/utility/Group-Object.cs | 4 +-- .../utility/ImplicitRemotingCommands.cs | 6 ++-- .../utility/MarkdownOptionCommands.cs | 2 +- .../commands/utility/Select-Object.cs | 2 +- .../Common/WebRequestPSCmdlet.Common.cs | 20 ++++++------- .../WebCmdlet/ConvertFromJsonCommand.cs | 4 +-- .../utility/WebCmdlet/ConvertToJsonCommand.cs | 4 +-- .../commands/utility/Write-Object.cs | 2 +- .../commands/utility/WriteConsoleCmdlet.cs | 2 +- .../host/msh/StartTranscriptCmdlet.cs | 2 +- .../Commands/NewLocalUserCommand.cs | 6 ++-- .../Commands/SetLocalUserCommand.cs | 4 +-- .../security/CertificateCommands.cs | 2 +- .../InvokeWSManAction.cs | 2 +- src/Microsoft.WSMan.Management/PingWSMan.cs | 2 +- .../WSManConnections.cs | 2 +- .../WSManInstance.cs | 8 +++--- .../engine/GetCommandCommand.cs | 6 ++-- .../engine/InternalCommands.cs | 2 +- .../engine/Modules/GetModuleCommand.cs | 6 ++-- .../engine/Modules/ImportModuleCommand.cs | 2 +- .../Modules/NewModuleManifestCommand.cs | 2 +- .../engine/MshCmdlet.cs | 4 +-- .../engine/ParameterBinderBase.cs | 2 +- .../engine/SessionStateContainer.cs | 2 +- .../engine/hostifaces/History.cs | 6 ++-- .../remoting/commands/ConnectPSSession.cs | 2 +- .../commands/NewPSSessionOptionCommand.cs | 4 +-- .../remoting/commands/PSRemotingCmdlet.cs | 4 +-- .../remoting/commands/PushRunspaceCommand.cs | 4 +-- .../remoting/commands/ReceivePSSession.cs | 2 +- .../engine/remoting/commands/StartJob.cs | 2 +- .../engine/remoting/commands/WaitJob.cs | 2 +- .../remoting/commands/getrunspacecommand.cs | 2 +- .../remoting/commands/newrunspacecommand.cs | 4 +-- .../help/UpdateHelpCommand.cs | 2 +- .../namespaces/FileSystemProvider.cs | 2 +- .../assets/ExpTest/ExpTest.cs | 4 +-- 56 files changed, 137 insertions(+), 137 deletions(-) diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs index b8ebc9adaef..1c39e01273b 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs @@ -923,7 +923,7 @@ internal void NewCimSession(NewCimSessionCommand cmdlet, CimTestCimSessionContext context = new(proxy, wrapper); proxy.ContextObject = context; // Skip test the connection if user intend to - if (cmdlet.SkipTestConnection.IsPresent) + if (cmdlet.SkipTestConnection) { AddSessionToCache(proxy.CimSession, context, new CmdletOperationBase(cmdlet)); } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs index 5cdc168ae24..06089e98c0a 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs @@ -654,7 +654,7 @@ private void EnablePSSemantics() /// public SwitchParameter KeyOnly { - set { this.OperationOptions.KeysOnly = value.IsPresent; } + set { this.OperationOptions.KeysOnly = value; } } /// @@ -664,7 +664,7 @@ public SwitchParameter Shallow { set { - if (value.IsPresent) + if (value) { this.OperationOptions.Flags = CimOperationFlags.PolymorphismShallow; } diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/ExportCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/ExportCounterCommand.cs index 9385e55909f..c51dd3d91f1 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/ExportCounterCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/ExportCounterCommand.cs @@ -188,7 +188,7 @@ protected override void BeginProcessing() // SetOutputFormat(); - if (Circular.IsPresent && _maxSize == 0) + if (Circular && _maxSize == 0) { string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterCircularNoMaxSize")); Exception exc = new Exception(msg); @@ -255,7 +255,7 @@ protected override void ProcessRecord() ReportPdhError(res, true); } - res = _pdhHelper.OpenLogForWriting(_resolvedPath, _outputFormat, Force.IsPresent, _maxSize * 1024 * 1024, Circular.IsPresent, null); + res = _pdhHelper.OpenLogForWriting(_resolvedPath, _outputFormat, Force, _maxSize * 1024 * 1024, Circular, null); if (res == PdhResults.PDH_FILE_ALREADY_EXISTS) { string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterFileExists"), _resolvedPath); diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs index 0122ad1941f..3879764c0ba 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs @@ -200,7 +200,7 @@ protected override void BeginProcessing() return; } - if (Continuous.IsPresent && _maxSamplesSpecified) + if (Continuous && _maxSamplesSpecified) { Exception exc = new(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples"))); ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null)); @@ -488,7 +488,7 @@ private void ProcessGetCounter() bool bSkip = true; uint sampleReads = 0; - if (Continuous.IsPresent) + if (Continuous) { _maxSamples = KEEP_ON_SAMPLING; } diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs index c7a07bab6ec..de3afebecc4 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs @@ -525,7 +525,7 @@ private void ProcessListLog() // // Skip direct channels matching the wildcard unless -Force is present. // - if (!Force.IsPresent && + if (!Force && WildcardPattern.ContainsWildcardCharacters(logPattern) && (logObj.LogType == EventLogType.Debug || logObj.LogType == EventLogType.Analytical)) @@ -624,7 +624,7 @@ private void ProcessFilterXml() { using (EventLogSession eventLogSession = CreateSession()) { - if (!Oldest.IsPresent) + if (!Oldest) { // // Do minimal parsing of xmlQuery to determine if any direct channels or ETL files are in it. @@ -1544,7 +1544,7 @@ private void CheckHashTableForQueryPathPresence(Hashtable hash) // private void TerminateForNonEvtxFileWithoutOldest(string fileName) { - if (!Oldest.IsPresent) + if (!Oldest) { if (System.IO.Path.GetExtension(fileName).Equals(".etl", StringComparison.OrdinalIgnoreCase) || System.IO.Path.GetExtension(fileName).Equals(".evt", StringComparison.OrdinalIgnoreCase)) @@ -1584,7 +1584,7 @@ private bool ValidateLogName(string logName, EventLogSession eventLogSession) return false; } - if (!Oldest.IsPresent) + if (!Oldest) { if (logObj.LogType == EventLogType.Debug || logObj.LogType == EventLogType.Analytical) { @@ -1896,7 +1896,7 @@ private void AddLogsForProviderToInternalMap(EventLogSession eventLogSession, st EventLogConfiguration logObj = new(logLink.LogName, eventLogSession); if (logObj.LogType == EventLogType.Debug || logObj.LogType == EventLogType.Analytical) { - if (!Force.IsPresent) + if (!Force) { continue; } @@ -1988,7 +1988,7 @@ private void FindLogNamesMatchingWildcards(EventLogSession eventLogSession, IEnu if (logObj.LogType == EventLogType.Debug || logObj.LogType == EventLogType.Analytical) { - if (WildcardPattern.ContainsWildcardCharacters(logPattern) && !Force.IsPresent) + if (WildcardPattern.ContainsWildcardCharacters(logPattern) && !Force) { continue; } diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs index 3e26b2e2e98..be2ee1e1276 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs @@ -143,7 +143,7 @@ private StartableJob DoCreateQueryJob(TSession sessionForJob, QueryBuilder query queryJob.SuppressOutputForwarding = true; } - bool discardNonPipelineResults = (actionAgainstResults != null) || !this.AsJob.IsPresent; + bool discardNonPipelineResults = (actionAgainstResults != null) || !this.AsJob; HandleJobOutput( queryJob, sessionForJob, @@ -225,7 +225,7 @@ private StartableJob DoCreateStaticMethodInvocationJob(TSession sessionForJob, M if (methodInvocationJob != null) { - bool discardNonPipelineResults = !this.AsJob.IsPresent; + bool discardNonPipelineResults = !this.AsJob; HandleJobOutput( methodInvocationJob, sessionForJob, @@ -379,7 +379,7 @@ public override void ProcessRecord(QueryBuilder query) StartableJob childJob = this.DoCreateQueryJob(sessionForJob, query, actionAgainstResults: null); if (childJob != null) { - if (!this.AsJob.IsPresent) + if (!this.AsJob) { _parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None); } @@ -416,7 +416,7 @@ public override void ProcessRecord(QueryBuilder query, MethodInvocationInfo meth objectInstance, methodInvocationInfo, passThru, - closureOverAsJob.IsPresent); + closureOverAsJob); if (methodInvocationJob != null) { @@ -426,7 +426,7 @@ public override void ProcessRecord(QueryBuilder query, MethodInvocationInfo meth if (queryJob != null) { - if (!this.AsJob.IsPresent) + if (!this.AsJob) { _parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, queryJob, ThrottlingJob.ChildJobFlags.CreatesChildJobs); } @@ -583,10 +583,10 @@ public override void ProcessRecord(TObjectInstance objectInstance, MethodInvocat foreach (TSession sessionForJob in this.GetSessionsToActAgainst(objectInstance)) { - StartableJob childJob = this.DoCreateInstanceMethodInvocationJob(sessionForJob, objectInstance, methodInvocationInfo, passThru, this.AsJob.IsPresent); + StartableJob childJob = this.DoCreateInstanceMethodInvocationJob(sessionForJob, objectInstance, methodInvocationInfo, passThru, this.AsJob); if (childJob != null) { - if (!this.AsJob.IsPresent) + if (!this.AsJob) { _parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None); } @@ -611,7 +611,7 @@ public override void ProcessRecord(MethodInvocationInfo methodInvocationInfo) StartableJob childJob = this.DoCreateStaticMethodInvocationJob(sessionForJob, methodInvocationInfo); if (childJob != null) { - if (!this.AsJob.IsPresent) + if (!this.AsJob) { _parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None); } @@ -628,15 +628,15 @@ public override void ProcessRecord(MethodInvocationInfo methodInvocationInfo) /// public override void BeginProcessing() { - if (this.AsJob.IsPresent) + if (this.AsJob) { MshCommandRuntime commandRuntime = (MshCommandRuntime)this.Cmdlet.CommandRuntime; // PSCmdlet.CommandRuntime is always MshCommandRuntime string conflictingParameter = null; - if (commandRuntime.WhatIf.IsPresent) + if (commandRuntime.WhatIf) { conflictingParameter = "WhatIf"; } - else if (commandRuntime.Confirm.IsPresent) + else if (commandRuntime.Confirm) { conflictingParameter = "Confirm"; } @@ -656,7 +656,7 @@ public override void BeginProcessing() jobName: this.GenerateParentJobName(), jobTypeName: CIMJobType, maximumConcurrentChildJobs: this.ThrottleLimit, - cmdletMode: !this.AsJob.IsPresent); + cmdletMode: !this.AsJob); } /// @@ -665,7 +665,7 @@ public override void BeginProcessing() public override void EndProcessing() { _parentJob.EndOfChildJobs(); - if (this.AsJob.IsPresent) + if (this.AsJob) { this.Cmdlet.WriteObject(_parentJob); this.Cmdlet.JobRepository.Add(_parentJob); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs index 0ea1c91aae6..34119a93d2d 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs @@ -1198,7 +1198,7 @@ public void Dispose() protected override void ProcessRecord() { object[] flags = new object[] { 1, 0 }; - if (Force.IsPresent) + if (Force) flags[0] = forcedShutdown; ProcessWSManProtocol(flags); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs index 27f812c7a80..d0600f0f11e 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetWMIObjectCommand.cs @@ -210,7 +210,7 @@ protected override void BeginProcessing() } else { - if (List.IsPresent) + if (List) { if (!this.ValidateClassFormat()) { @@ -230,7 +230,7 @@ protected override void BeginProcessing() foreach (string name in ComputerName) { - if (this.Recurse.IsPresent) + if (this.Recurse) { Queue namespaceElement = new Queue(); namespaceElement.Enqueue(this.Namespace); @@ -349,7 +349,7 @@ protected override void BeginProcessing() } // When -List is not specified and -Recurse is specified, we need the -Class parameter to compose the right query string - if (this.Recurse.IsPresent && string.IsNullOrEmpty(Class)) + if (this.Recurse && string.IsNullOrEmpty(Class)) { string errorMsg = string.Format(CultureInfo.InvariantCulture, WmiResources.WmiParameterMissing, "-Class"); ErrorRecord er = new ErrorRecord(new InvalidOperationException(errorMsg), "InvalidOperationException", ErrorCategory.InvalidOperation, null); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index c959cfcb33e..ca7b3ee1595 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -550,7 +550,7 @@ protected override void ProcessRecord() { foreach (Process process in MatchingProcesses()) { - if (Module.IsPresent && FileVersionInfo.IsPresent) + if (Module && FileVersionInfo) { ProcessModule tempmodule = null; try @@ -594,7 +594,7 @@ protected override void ProcessRecord() WriteNonTerminatingError(process, exception, ProcessResources.CouldNotEnumerateModuleFileVer, "CouldNotEnumerateModuleFileVer", ErrorCategory.PermissionDenied); } } - else if (Module.IsPresent) + else if (Module) { try { @@ -627,7 +627,7 @@ protected override void ProcessRecord() WriteNonTerminatingError(process, exception, ProcessResources.CouldNotEnumerateModules, "CouldNotEnumerateModules", ErrorCategory.PermissionDenied); } } - else if (FileVersionInfo.IsPresent) + else if (FileVersionInfo) { try { @@ -670,7 +670,7 @@ protected override void ProcessRecord() } else { - WriteObject(IncludeUserName.IsPresent ? AddUserNameToProcess(process) : process); + WriteObject(IncludeUserName ? AddUserNameToProcess(process) : process); } } } @@ -2131,7 +2131,7 @@ protected override void BeginProcessing() #endif } - if (PassThru.IsPresent) + if (PassThru) { if (process != null) { @@ -2145,7 +2145,7 @@ protected override void BeginProcessing() } } - if (Wait.IsPresent) + if (Wait) { if (process != null) { diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs index 739baa15bab..db6561ed68d 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs @@ -637,13 +637,13 @@ protected override void ProcessRecord() { foreach (ServiceController service in MatchingServices()) { - if (!DependentServices.IsPresent && !RequiredServices.IsPresent) + if (!DependentServices && !RequiredServices) { WriteObject(AddProperties(scManagerHandle, service)); } else { - if (DependentServices.IsPresent) + if (DependentServices) { foreach (ServiceController dependantserv in service.DependentServices) { @@ -651,7 +651,7 @@ protected override void ProcessRecord() } } - if (RequiredServices.IsPresent) + if (RequiredServices) { foreach (ServiceController servicedependedon in service.ServicesDependedOn) { @@ -1932,7 +1932,7 @@ protected override void ProcessRecord() SetServiceSecurityDescriptor(service, SecurityDescriptorSddl, hService); } - if (PassThru.IsPresent) + if (PassThru) { // To display the service, refreshing the service would not show the display name after updating ServiceController displayservice = new(Name); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs index 17c9ab9a5d3..e820e270f1f 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs @@ -298,7 +298,7 @@ protected override void StopProcessing() private void SetCountForTcpTest() { - if (Repeat.IsPresent) + if (Repeat) { Count = int.MaxValue; } @@ -312,7 +312,7 @@ private void ProcessConnectionByTCPPort(string targetNameOrAddress) { if (!TryResolveNameOrAddress(targetNameOrAddress, out _, out IPAddress? targetAddress)) { - if (Quiet.IsPresent) + if (Quiet) { WriteObject(false); } @@ -370,7 +370,7 @@ private void ProcessConnectionByTCPPort(string targetNameOrAddress) stopwatch.Reset(); } - if (!Detailed.IsPresent) + if (!Detailed) { WriteObject(status == SocketError.Success); return; @@ -406,7 +406,7 @@ private void ProcessTraceroute(string targetNameOrAddress) if (!TryResolveNameOrAddress(targetNameOrAddress, out string resolvedTargetName, out IPAddress? targetAddress)) { - if (!Quiet.IsPresent) + if (!Quiet) { WriteObject(false); } @@ -415,7 +415,7 @@ private void ProcessTraceroute(string targetNameOrAddress) } int currentHop = 1; - PingOptions pingOptions = new(currentHop, DontFragment.IsPresent); + PingOptions pingOptions = new(currentHop, DontFragment); PingReply reply; PingReply discoveryReply; int timeout = TimeoutSeconds * 1000; @@ -475,7 +475,7 @@ private void ProcessTraceroute(string targetNameOrAddress) { reply = SendCancellablePing(hopAddress, timeout, buffer, pingOptions, timer); - if (!Quiet.IsPresent) + if (!Quiet) { var status = new PingStatus( Source, @@ -524,7 +524,7 @@ private void ProcessTraceroute(string targetNameOrAddress) && (discoveryReply.Status == IPStatus.TtlExpired || discoveryReply.Status == IPStatus.TimedOut)); - if (Quiet.IsPresent) + if (Quiet) { WriteObject(currentHop <= MaxHops); } @@ -551,7 +551,7 @@ private void ProcessMTUSize(string targetNameOrAddress) PingReply? reply, replyResult = null; if (!TryResolveNameOrAddress(targetNameOrAddress, out string resolvedTargetName, out IPAddress? targetAddress)) { - if (Quiet.IsPresent) + if (Quiet) { WriteObject(-1); } @@ -640,7 +640,7 @@ private void ProcessMTUSize(string targetNameOrAddress) return; } - if (Quiet.IsPresent) + if (Quiet) { WriteObject(CurrentMTUSize); } @@ -683,7 +683,7 @@ private void ProcessPing(string targetNameOrAddress) { if (!TryResolveNameOrAddress(targetNameOrAddress, out string resolvedTargetName, out IPAddress? targetAddress)) { - if (Quiet.IsPresent) + if (Quiet) { WriteObject(false); } @@ -695,7 +695,7 @@ private void ProcessPing(string targetNameOrAddress) byte[] buffer = GetSendBuffer(BufferSize); PingReply reply; - PingOptions pingOptions = new(MaxHops, DontFragment.IsPresent); + PingOptions pingOptions = new(MaxHops, DontFragment); int timeout = TimeoutSeconds * 1000; int delay = Delay * 1000; @@ -720,7 +720,7 @@ private void ProcessPing(string targetNameOrAddress) continue; } - if (Quiet.IsPresent) + if (Quiet) { // Return 'true' only if all pings have completed successfully. quietResult &= reply.Status == IPStatus.Success; @@ -743,7 +743,7 @@ private void ProcessPing(string targetNameOrAddress) } } - if (Quiet.IsPresent) + if (Quiet) { WriteObject(quietResult); } @@ -807,7 +807,7 @@ private bool TryResolveNameOrAddress( } catch (Exception ex) { - if (!Quiet.IsPresent) + if (!Quiet) { string message = StringUtil.Format( TestConnectionResources.NoPingResult, diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs index 8fdb2c55acd..d5dd999b254 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs @@ -291,7 +291,7 @@ protected override void ProcessRecord() // will not recognize the new time zone settings TimeZoneInfo.ClearCachedData(); - if (PassThru.IsPresent) + if (PassThru) { // return the TimeZoneInfo object for the (new) current local time zone WriteObject(TimeZoneInfo.Local); @@ -314,7 +314,7 @@ protected override void ProcessRecord() } else { - if (PassThru.IsPresent) + if (PassThru) { // show the user the time zone settings that would have been used. WriteObject(InputObject); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/WMIHelper.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/WMIHelper.cs index 31670a7d632..67c4785fd4b 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/WMIHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/WMIHelper.cs @@ -838,7 +838,7 @@ private void ConnectGetWMI() _state = WmiState.Running; RaiseWmiOperationState(null, WmiState.Running); ConnectionOptions options = getObject.GetConnectionOption(); - if (getObject.List.IsPresent) + if (getObject.List) { if (!getObject.ValidateClassFormat()) { @@ -855,7 +855,7 @@ private void ConnectGetWMI() try { - if (getObject.Recurse.IsPresent) + if (getObject.Recurse) { ArrayList namespaceArray = new ArrayList(); ArrayList sinkArray = new ArrayList(); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs index 3f91d597e57..6f84b975720 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs @@ -222,7 +222,7 @@ protected override void BeginProcessing() { if (pr.Name.Equals("UseDefaultCredentials", StringComparison.OrdinalIgnoreCase)) { - if (UseDefaultCredential.IsPresent) + if (UseDefaultCredential) { bool flag = true; pr.SetValue(instance, flag as object, null); @@ -322,7 +322,7 @@ private Assembly GenerateWebServiceProxyAssembly(string NameSpace, string ClassN DiscoveryClientProtocol dcp = new DiscoveryClientProtocol(); // if paramset is defaultcredential, set the flag in wcclient - if (_usedefaultcredential.IsPresent) + if (_usedefaultcredential) dcp.UseDefaultCredentials = true; // if paramset is credential, assign the credentials diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index 7dc0a9c3556..47afd819538 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -1013,7 +1013,7 @@ private void SourceCodeProcessing() compilationOptions = GetDefaultCompilationOptions(); } - if (!IgnoreWarnings.IsPresent) + if (!IgnoreWarnings) { compilationOptions = compilationOptions.WithGeneralDiagnosticOption(defaultDiagnosticOption); } @@ -1050,7 +1050,7 @@ private void SourceCodeProcessing() break; } - if (!string.IsNullOrEmpty(_outputAssembly) && !PassThru.IsPresent) + if (!string.IsNullOrEmpty(_outputAssembly) && !PassThru) { CompileToAssembly(syntaxTrees, compilationOptions, emitOptions); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs index fa49c33d2ab..fc270ab2647 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs @@ -307,7 +307,7 @@ protected override void ProcessRecord() } // write headers (row1: typename + row2: column names) - if (!_isActuallyAppending && !NoHeader.IsPresent) + if (!_isActuallyAppending && !NoHeader) { if (NoTypeInformation == false) { @@ -732,7 +732,7 @@ protected override void ProcessRecord() { _propertyNames = ExportCsvHelper.BuildPropertyNames(InputObject, _propertyNames); - if (!NoHeader.IsPresent) + if (!NoHeader) { if (NoTypeInformation == false) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs index 574ca39426d..f3a1f943f68 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs @@ -99,7 +99,7 @@ public SwitchParameter PassThru { get { return OutputMode == OutputModeOption.Multiple ? new SwitchParameter(true) : new SwitchParameter(false); } - set { this.OutputMode = value.IsPresent ? OutputModeOption.Multiple : OutputModeOption.None; } + set { this.OutputMode = value ? OutputModeOption.Multiple : OutputModeOption.None; } } #endregion Input Parameters diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetUnique.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetUnique.cs index 09bc78d9693..ad9d6f392db 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetUnique.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetUnique.cs @@ -84,7 +84,7 @@ protected override void ProcessRecord() if (string.Equals( inputString, _lastObjectAsString, - CaseInsensitive.IsPresent ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture)) + CaseInsensitive ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture)) { isUnique = false; } @@ -98,7 +98,7 @@ protected override void ProcessRecord() _comparer ??= new ObjectCommandComparer( ascending: true, CultureInfo.CurrentCulture, - caseSensitive: !CaseInsensitive.IsPresent); + caseSensitive: !CaseInsensitive); isUnique = (_comparer.Compare(InputObject, _lastObject) != 0); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs index 1f527258939..13db0e47d6b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs @@ -512,9 +512,9 @@ protected override void EndProcessing() s_tracer.WriteLine(_groups.Count); if (_groups.Count > 0) { - if (AsHashTable.IsPresent) + if (AsHashTable) { - StringComparer comparer = CaseSensitive.IsPresent + StringComparer comparer = CaseSensitive ? StringComparer.CurrentCulture : StringComparer.CurrentCultureIgnoreCase; var hashtable = new Hashtable(comparer); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs index d01d144caca..d36a5f10f15 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs @@ -63,7 +63,7 @@ public SwitchParameter Force set { - _force = value.IsPresent; + _force = value; } } @@ -131,7 +131,7 @@ protected override void BeginProcessing() ThrowTerminatingError(error); } - DirectoryInfo directory = PathUtils.CreateModuleDirectory(this, this.OutputModule, this.Force.IsPresent); + DirectoryInfo directory = PathUtils.CreateModuleDirectory(this, this.OutputModule, this.Force); // Creating a temporary directory where files will be created. // Then, copy the files from this location to the location specified in OutputModule @@ -886,7 +886,7 @@ private bool IsCommandNameAllowedForImport(string commandName) throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } - if (this.AllowClobber.IsPresent) + if (this.AllowClobber) { return true; } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs index cd18f33c41d..02eb0022086 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs @@ -172,7 +172,7 @@ protected override void EndProcessing() var setOption = PSMarkdownOptionInfoCache.Set(this.CommandInfo, mdOptionInfo); - if (PassThru.IsPresent) + if (PassThru) { WriteObject(setOption); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs index 9db27335da5..61b39bb9a0e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs @@ -642,7 +642,7 @@ private void FilteredWriteObject(PSObject obj, List addedNotePro ObjectCommandComparer comparer = new( ascending: true, CultureInfo.CurrentCulture, - caseSensitive: !CaseInsensitive.IsPresent); + caseSensitive: !CaseInsensitive); if ((comparer.Compare(obj.BaseObject, uniqueObj.WrittenObject.BaseObject) == 0) && (uniqueObj.NotePropertyCount == addedNoteProperties.Count)) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index 7a784a1e495..17a12ddf6da 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -513,7 +513,7 @@ public abstract class WebRequestPSCmdlet : PSCmdlet, IDisposable /// /// Determines whether writing to a file should Resume and append rather than overwrite. /// - internal bool ShouldResume => Resume.IsPresent && _resumeSuccess; + internal bool ShouldResume => Resume && _resumeSuccess; internal bool ShouldSaveToOutFile => !string.IsNullOrEmpty(OutFile); @@ -546,7 +546,7 @@ protected override void ProcessRecord() // If the request contains an authorization header and PreserveAuthorizationOnRedirect is not set, // it needs to be stripped on the first redirect. - bool keepAuthorizationOnRedirect = PreserveAuthorizationOnRedirect.IsPresent + bool keepAuthorizationOnRedirect = PreserveAuthorizationOnRedirect && WebSession.Headers.ContainsKey(HttpKnownHeaderNames.Authorization); bool handleRedirect = keepAuthorizationOnRedirect || AllowInsecureRedirect || PreserveHttpMethodOnRedirect; @@ -580,7 +580,7 @@ protected override void ProcessRecord() // Check if the Resume range was not satisfiable because the file already completed downloading. // This happens when the local file is the same size as the remote file. - if (Resume.IsPresent + if (Resume && response.StatusCode == HttpStatusCode.RequestedRangeNotSatisfiable && response.Content.Headers.ContentRange.HasLength && response.Content.Headers.ContentRange.Length == _resumeFileSize) @@ -885,14 +885,14 @@ internal virtual void ValidateParameters() } // Output ?? - if (PassThru.IsPresent && OutFile is null) + if (PassThru && OutFile is null) { ErrorRecord error = GetValidationError(WebCmdletStrings.OutFileMissing, "WebCmdletOutFileMissingException", nameof(PassThru)); ThrowTerminatingError(error); } // Resume requires OutFile. - if (Resume.IsPresent && OutFile is null) + if (Resume && OutFile is null) { ErrorRecord error = GetValidationError(WebCmdletStrings.OutFileMissing, "WebCmdletOutFileMissingException", nameof(Resume)); ThrowTerminatingError(error); @@ -901,7 +901,7 @@ internal virtual void ValidateParameters() _qualifiedOutFile = ShouldSaveToOutFile ? QualifiedOutFile : null; // OutFile must not be a directory to use Resume. - if (Resume.IsPresent && Directory.Exists(_qualifiedOutFile)) + if (Resume && Directory.Exists(_qualifiedOutFile)) { ErrorRecord error = GetValidationError(WebCmdletStrings.ResumeNotFilePath, "WebCmdletResumeNotFilePathException", _qualifiedOutFile); ThrowTerminatingError(error); @@ -972,7 +972,7 @@ internal virtual void PrepareSession() // Proxy and NoProxy parameters are mutually exclusive. // If NoProxy is provided, WebSession will turn off the proxy // and if Proxy is provided NoProxy will be turned off. - if (NoProxy.IsPresent) + if (NoProxy) { WebSession.NoProxy = true; } @@ -1013,7 +1013,7 @@ internal virtual void PrepareSession() WebSession.UnixSocket = UnixSocket; - WebSession.SkipCertificateCheck = SkipCertificateCheck.IsPresent; + WebSession.SkipCertificateCheck = SkipCertificateCheck; // Store the other supplied headers if (Headers is not null) @@ -1134,7 +1134,7 @@ internal virtual HttpRequestMessage GetRequest(Uri uri) // If the file to resume downloading exists, create the Range request header using the file size. // If not, create a Range to request the entire file. - if (Resume.IsPresent) + if (Resume) { FileInfo fileInfo = new(QualifiedOutFile); @@ -1354,7 +1354,7 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM // Request again without the Range header because the server indicated the range was not satisfiable. // This happens when the local file is larger than the remote file. // If the size of the remote file is the same as the local file, there is nothing to resume. - if (Resume.IsPresent + if (Resume && response.StatusCode == HttpStatusCode.RequestedRangeNotSatisfiable && (response.Content.Headers.ContentRange.HasLength && response.Content.Headers.ContentRange.Length != _resumeFileSize)) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs index 82e1277e00c..d017dda843b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs @@ -119,14 +119,14 @@ protected override void EndProcessing() private bool ConvertFromJsonHelper(string input) { ErrorRecord error = null; - object result = JsonObject.ConvertFromJson(input, AsHashtable.IsPresent, Depth, DateKind, out error); + object result = JsonObject.ConvertFromJson(input, AsHashtable, Depth, DateKind, out error); if (error != null) { ThrowTerminatingError(error); } - WriteObject(result, !NoEnumerate.IsPresent); + WriteObject(result, !NoEnumerate); return (result != null); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs index 173d999b06d..79e4e259edf 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs @@ -120,8 +120,8 @@ protected override void EndProcessing() var context = new JsonObject.ConvertToJsonContext( Depth, - EnumsAsStrings.IsPresent, - Compress.IsPresent, + EnumsAsStrings, + Compress, EscapeHandling, targetCmdlet: this, _cancellationSource.Token); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Write-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Write-Object.cs index 2d7fc9d233d..783e09c2499 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Write-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Write-Object.cs @@ -37,7 +37,7 @@ protected override void ProcessRecord() return; } - WriteObject(InputObject, !NoEnumerate.IsPresent); + WriteObject(InputObject, !NoEnumerate); } } #endregion diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs index 48d84636ce2..a49f1236023 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs @@ -107,7 +107,7 @@ protected override void ProcessRecord() HostInformationMessage informationMessage = new(); informationMessage.Message = result; - informationMessage.NoNewLine = NoNewline.IsPresent; + informationMessage.NoNewLine = NoNewline; try { diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs index 18725b5ddb7..99482488c94 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs @@ -234,7 +234,7 @@ protected override void BeginProcessing() System.Management.Automation.Remoting.PSSenderInfo psSenderInfo = this.SessionState.PSVariable.GetValue("PSSenderInfo") as System.Management.Automation.Remoting.PSSenderInfo; - Host.UI.StartTranscribing(effectiveFilePath, psSenderInfo, IncludeInvocationHeader.ToBool(), UseMinimalHeader.IsPresent); + Host.UI.StartTranscribing(effectiveFilePath, psSenderInfo, IncludeInvocationHeader.ToBool(), UseMinimalHeader); // ch.StartTranscribing(effectiveFilePath, Append); diff --git a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/NewLocalUserCommand.cs b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/NewLocalUserCommand.cs index d3402b5a4c9..dd4cb5c1a26 100644 --- a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/NewLocalUserCommand.cs +++ b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/NewLocalUserCommand.cs @@ -207,7 +207,7 @@ public System.Management.Automation.SwitchParameter UserMayNotChangePassword /// protected override void BeginProcessing() { - if (this.HasParameter("AccountExpires") && AccountNeverExpires.IsPresent) + if (this.HasParameter("AccountExpires") && AccountNeverExpires) { InvalidParametersException ex = new InvalidParametersException("AccountExpires", "AccountNeverExpires"); ThrowTerminatingError(ex.MakeErrorRecord()); @@ -255,11 +255,11 @@ protected override void ProcessRecord() } } - if (AccountNeverExpires.IsPresent) + if (AccountNeverExpires) user.AccountExpires = null; // Password will be null if NoPassword was given - user = sam.CreateLocalUser(user, Password, PasswordNeverExpires.IsPresent); + user = sam.CreateLocalUser(user, Password, PasswordNeverExpires); WriteObject(user); } diff --git a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/SetLocalUserCommand.cs b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/SetLocalUserCommand.cs index 3bfdc24ac03..47e7f98a532 100644 --- a/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/SetLocalUserCommand.cs +++ b/src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Commands/SetLocalUserCommand.cs @@ -213,7 +213,7 @@ public bool UserMayChangePassword /// protected override void BeginProcessing() { - if (this.HasParameter("AccountExpires") && AccountNeverExpires.IsPresent) + if (this.HasParameter("AccountExpires") && AccountNeverExpires) { InvalidParametersException ex = new InvalidParametersException("AccountExpires", "AccountNeverExpires"); ThrowTerminatingError(ex.MakeErrorRecord()); @@ -287,7 +287,7 @@ protected override void ProcessRecord() } } - if (AccountNeverExpires.IsPresent) + if (AccountNeverExpires) delta.AccountExpires = null; sam.UpdateLocalUser(user, delta, Password, passwordNeverExpires); diff --git a/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs b/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs index e3a386ee507..59d42669baa 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs @@ -138,7 +138,7 @@ protected override void ProcessRecord() } else { - if (Password == null && !NoPromptForPassword.IsPresent) + if (Password == null && !NoPromptForPassword) { try { diff --git a/src/Microsoft.WSMan.Management/InvokeWSManAction.cs b/src/Microsoft.WSMan.Management/InvokeWSManAction.cs index da92a680ab3..3fee52d03d4 100644 --- a/src/Microsoft.WSMan.Management/InvokeWSManAction.cs +++ b/src/Microsoft.WSMan.Management/InvokeWSManAction.cs @@ -276,7 +276,7 @@ protected override void ProcessRecord() IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, null, null, m_wsmanObject, resourceuri); // create the session object - m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent); + m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl); string rootNode = helper.GetRootNodeName(helper.WSManOp, m_resource.ResourceUri, action); string input = helper.ProcessInput(m_wsmanObject, filepath, helper.WSManOp, rootNode, valueset, m_resource, m_session); diff --git a/src/Microsoft.WSMan.Management/PingWSMan.cs b/src/Microsoft.WSMan.Management/PingWSMan.cs index 88b443a6ef0..39533907832 100644 --- a/src/Microsoft.WSMan.Management/PingWSMan.cs +++ b/src/Microsoft.WSMan.Management/PingWSMan.cs @@ -150,7 +150,7 @@ protected override void ProcessRecord() IWSManSession m_SessionObj = null; try { - m_SessionObj = helper.CreateSessionObject(wsmanObject, Authentication, null, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent); + m_SessionObj = helper.CreateSessionObject(wsmanObject, Authentication, null, Credential, connectionStr, CertificateThumbprint, usessl); m_SessionObj.Timeout = 1000; // 1 sec. we are putting this low so that Test-WSMan can return promptly if the server goes unresponsive. XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(m_SessionObj.Identify(0)); diff --git a/src/Microsoft.WSMan.Management/WSManConnections.cs b/src/Microsoft.WSMan.Management/WSManConnections.cs index cac5196740f..ad380f4f161 100644 --- a/src/Microsoft.WSMan.Management/WSManConnections.cs +++ b/src/Microsoft.WSMan.Management/WSManConnections.cs @@ -288,7 +288,7 @@ protected override void BeginProcessing() helper.AssertError(helper.GetResourceMsgFromResourcetext("ConnectFailure"), false, computername); } - helper.CreateWsManConnection(ParameterSetName, connectionuri, port, computername, applicationname, usessl.IsPresent, Authentication, sessionoption, Credential, CertificateThumbprint); + helper.CreateWsManConnection(ParameterSetName, connectionuri, port, computername, applicationname, usessl, Authentication, sessionoption, Credential, CertificateThumbprint); } } #endregion diff --git a/src/Microsoft.WSMan.Management/WSManInstance.cs b/src/Microsoft.WSMan.Management/WSManInstance.cs index c96b002123d..be0ab6546ad 100644 --- a/src/Microsoft.WSMan.Management/WSManInstance.cs +++ b/src/Microsoft.WSMan.Management/WSManInstance.cs @@ -589,7 +589,7 @@ protected override void ProcessRecord() try { IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, fragment, dialect, m_wsmanObject, resourceuri); - m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent); + m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl); if (!enumerate) { @@ -969,7 +969,7 @@ protected override void ProcessRecord() } IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, fragment, dialect, m_wsmanObject, resourceuri); - m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent); + m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl); string rootNode = helper.GetRootNodeName(helper.WSManOp, m_resource.ResourceUri, null); string input = helper.ProcessInput(m_wsmanObject, filepath, helper.WSManOp, rootNode, valueset, m_resource, m_session); @@ -1264,7 +1264,7 @@ protected override void ProcessRecord() } IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, null, null, m_wsmanObject, resourceuri); - m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent); + m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl); string ResourceURI = helper.GetURIWithFilter(resourceuri.ToString(), null, selectorset, helper.WSManOp); try { @@ -1565,7 +1565,7 @@ protected override void ProcessRecord() { IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, null, null, m_wsmanObject, resourceuri); // create the session object - m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent); + m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl); string rootNode = helper.GetRootNodeName(helper.WSManOp, m_resource.ResourceUri, null); string input = helper.ProcessInput(m_wsmanObject, filepath, helper.WSManOp, rootNode, valueset, m_resource, m_session); diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index 10e8334021b..35f7950e927 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -397,7 +397,7 @@ protected override void BeginProcessing() _commandScores = new List(); } - if (ShowCommandInfo.IsPresent && Syntax.IsPresent) + if (ShowCommandInfo && Syntax) { ThrowTerminatingError( new ErrorRecord( @@ -559,7 +559,7 @@ private void OutputResultsHelper(IEnumerable results) } else { - if (ShowCommandInfo.IsPresent) + if (ShowCommandInfo) { // Write output as ShowCommandCommandInfo object. WriteObject( @@ -1336,7 +1336,7 @@ private bool IsCommandMatch(ref CommandInfo current, out bool isDuplicate) if (isCommandMatch) { - if (Syntax.IsPresent && current is AliasInfo ai) + if (Syntax && current is AliasInfo ai) { // If the matching command was an alias, then use the resolved command // instead of the alias... diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index 844a965ac1e..64169750f26 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -2710,7 +2710,7 @@ public Version Version /// protected override void EndProcessing() { - if (_off.IsPresent) + if (_off) { _version = new Version(0, 0); } diff --git a/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs b/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs index 39c3e9c905e..a0d83487dd6 100644 --- a/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs @@ -149,7 +149,7 @@ private IEnumerable GetAvailableViaPsrpSessionCore(string[] module powerShell.AddCommand("Get-Module"); powerShell.AddParameter("ListAvailable", true); - if (Refresh.IsPresent) + if (Refresh) { powerShell.AddParameter("Refresh", true); } @@ -329,7 +329,7 @@ private void Dispose(bool disposing) private void AssertListAvailableMode() { - if (!this.ListAvailable.IsPresent) + if (!this.ListAvailable) { string errorMessage = Modules.RemoteDiscoveryWorksOnlyInListAvailableMode; ArgumentException argumentException = new ArgumentException(errorMessage); @@ -397,7 +397,7 @@ protected override void ProcessRecord() } else if (ParameterSetName.Equals(ParameterSet_AvailableLocally, StringComparison.OrdinalIgnoreCase)) { - if (ListAvailable.IsPresent) + if (ListAvailable) { GetAvailableLocallyModules(names, moduleSpecTable, this.All); } diff --git a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs index 05357bbb5e5..d218f9de252 100644 --- a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs @@ -1816,7 +1816,7 @@ private void Dispose(bool disposing) protected override void BeginProcessing() { // Make sure that only one of (Global | Scope) is specified - if (Global.IsPresent && _isScopeSpecified) + if (Global && _isScopeSpecified) { InvalidOperationException ioe = new InvalidOperationException(Modules.GlobalAndScopeParameterCannotBeSpecifiedTogether); ErrorRecord er = new ErrorRecord(ioe, "Modules_GlobalAndScopeParameterCannotBeSpecifiedTogether", diff --git a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs index 9346e7caa97..7d9c0ad2d0e 100644 --- a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs +++ b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs @@ -1181,7 +1181,7 @@ private void BuildPrivateDataInModuleManifest(StringBuilder result, StreamWriter BuildModuleManifest(result, nameof(IconUri), Modules.IconUri, IconUri != null, () => QuoteName(IconUri), streamWriter); BuildModuleManifest(result, nameof(ReleaseNotes), Modules.ReleaseNotes, !string.IsNullOrEmpty(ReleaseNotes), () => QuoteName(ReleaseNotes), streamWriter); BuildModuleManifest(result, nameof(Prerelease), Modules.Prerelease, !string.IsNullOrEmpty(Prerelease), () => QuoteName(Prerelease), streamWriter); - BuildModuleManifest(result, nameof(RequireLicenseAcceptance), Modules.RequireLicenseAcceptance, RequireLicenseAcceptance.IsPresent, () => RequireLicenseAcceptance.IsPresent ? "$true" : "$false", streamWriter); + BuildModuleManifest(result, nameof(RequireLicenseAcceptance), Modules.RequireLicenseAcceptance, RequireLicenseAcceptance, () => RequireLicenseAcceptance ? "$true" : "$false", streamWriter); BuildModuleManifest(result, nameof(ExternalModuleDependencies), Modules.ExternalModuleDependencies, ExternalModuleDependencies != null && ExternalModuleDependencies.Length > 0, () => QuoteNames(ExternalModuleDependencies, streamWriter), streamWriter); result.Append(" } "); diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs index 40095ad1472..bcb6b21b479 100644 --- a/src/System.Management.Automation/engine/MshCmdlet.cs +++ b/src/System.Management.Automation/engine/MshCmdlet.cs @@ -90,7 +90,7 @@ public bool IsPresent /// The corresponding boolean value. public static implicit operator bool(SwitchParameter switchParameter) { - return switchParameter.IsPresent; + return switchParameter._isPresent; } /// @@ -145,7 +145,7 @@ public override bool Equals(object obj) } else if (obj is SwitchParameter) { - return _isPresent == ((SwitchParameter)obj).IsPresent; + return _isPresent == (SwitchParameter)obj; } else { diff --git a/src/System.Management.Automation/engine/ParameterBinderBase.cs b/src/System.Management.Automation/engine/ParameterBinderBase.cs index 21868b1a28d..ec9631ffef8 100644 --- a/src/System.Management.Automation/engine/ParameterBinderBase.cs +++ b/src/System.Management.Automation/engine/ParameterBinderBase.cs @@ -1094,7 +1094,7 @@ private object CoerceTypeAsNeeded( if (currentValue is SwitchParameter) { - currentValue = ((SwitchParameter)currentValue).IsPresent; + currentValue = (SwitchParameter)currentValue; } boType = currentValue.GetType(); diff --git a/src/System.Management.Automation/engine/SessionStateContainer.cs b/src/System.Management.Automation/engine/SessionStateContainer.cs index fa8884b92e8..0104a41bad0 100644 --- a/src/System.Management.Automation/engine/SessionStateContainer.cs +++ b/src/System.Management.Automation/engine/SessionStateContainer.cs @@ -1335,7 +1335,7 @@ internal void GetChildItems( if (context.DynamicParameters is Microsoft.PowerShell.Commands.GetChildDynamicParameters dynParam) { - isFileOrDirectoryPresent = dynParam.File.IsPresent || dynParam.Directory.IsPresent; + isFileOrDirectoryPresent = dynParam.File || dynParam.Directory; } if (string.Equals(childName, "*", StringComparison.OrdinalIgnoreCase) && isFileOrDirectoryPresent) diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 00a090d4b22..fd45f3df4f0 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -310,7 +310,7 @@ internal HistoryInfo[] GetEntries(long id, long count, SwitchParameter newest) baseId = id; // get id,count,newest values - if (!newest.IsPresent) + if (!newest) { // get older entries @@ -390,7 +390,7 @@ internal HistoryInfo[] GetEntries(long id, long count, SwitchParameter newest) // eg if size is 5 and then the entries can be 7,6,1,2,3 if (_capacity != DefaultHistorySize) SmallestID = SmallestIDinBuffer(); - if (!newest.IsPresent) + if (!newest) { // get oldest count entries index = 1; @@ -485,7 +485,7 @@ internal HistoryInfo[] GetEntries(WildcardPattern wildcardpattern, long count, S SmallestID = SmallestIDinBuffer(); if (count != 0) { - if (!newest.IsPresent) + if (!newest) { long id = 1; if (_capacity != DefaultHistorySize) diff --git a/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs b/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs index b7474fe34c2..0360c7ffa93 100644 --- a/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs +++ b/src/System.Management.Automation/engine/remoting/commands/ConnectPSSession.cs @@ -930,7 +930,7 @@ private Collection GetConnectionObjects() if (ParameterSetName == ConnectPSSessionCommand.ComputerNameParameterSet || ParameterSetName == ConnectPSSessionCommand.ComputerNameGuidParameterSet) { - string scheme = UseSSL.IsPresent ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; + string scheme = UseSSL ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; foreach (string computerName in ComputerName) { diff --git a/src/System.Management.Automation/engine/remoting/commands/NewPSSessionOptionCommand.cs b/src/System.Management.Automation/engine/remoting/commands/NewPSSessionOptionCommand.cs index bb7641d2e5b..8f8d35268cc 100644 --- a/src/System.Management.Automation/engine/remoting/commands/NewPSSessionOptionCommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/NewPSSessionOptionCommand.cs @@ -401,8 +401,8 @@ protected override void BeginProcessing() result.MaximumConnectionRedirectionCount = this.MaximumRedirection; } - result.NoCompression = this.NoCompression.IsPresent; - result.NoMachineProfile = this.NoMachineProfile.IsPresent; + result.NoCompression = this.NoCompression; + result.NoMachineProfile = this.NoMachineProfile; result.MaximumReceivedDataSizePerCommand = _maxRecvdDataSizePerCommand; result.MaximumReceivedObjectSize = _maxRecvdObjectSize; diff --git a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs index 8a5df652470..c4aa961b5b1 100644 --- a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs +++ b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs @@ -1439,7 +1439,7 @@ protected virtual void CreateHelpersForSpecifiedComputerNames() // create helper objects for computer names RemoteRunspace remoteRunspace = null; - string scheme = UseSSL.IsPresent ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; + string scheme = UseSSL ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; for (int i = 0; i < ResolvedComputerNames.Length; i++) { @@ -1858,7 +1858,7 @@ protected virtual void CreateHelpersForSpecifiedContainerSession() // Hyper-V container uses Hype-V socket as transport. // Windows Server container uses named pipe as transport. // - connectionInfo = ContainerConnectionInfo.CreateContainerConnectionInfo(input, RunAsAdministrator.IsPresent, this.ConfigurationName); + connectionInfo = ContainerConnectionInfo.CreateContainerConnectionInfo(input, RunAsAdministrator, this.ConfigurationName); resolvedNameList.Add(connectionInfo.ComputerName); diff --git a/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs b/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs index bf456e85db2..a43b3912502 100644 --- a/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs @@ -687,7 +687,7 @@ private RemoteRunspace CreateRunspaceWhenComputerNameParameterSpecified() { WSManConnectionInfo connectionInfo = null; connectionInfo = new WSManConnectionInfo(); - string scheme = UseSSL.IsPresent ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; + string scheme = UseSSL ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; connectionInfo.ComputerName = resolvedComputerName; connectionInfo.Port = Port; connectionInfo.AppName = ApplicationName; @@ -1216,7 +1216,7 @@ private RemoteRunspace GetRunspaceForContainerSession() // Hyper-V container uses Hype-V socket as transport. // Windows Server container uses named pipe as transport. // - connectionInfo = ContainerConnectionInfo.CreateContainerConnectionInfo(ContainerId, RunAsAdministrator.IsPresent, this.ConfigurationName); + connectionInfo = ContainerConnectionInfo.CreateContainerConnectionInfo(ContainerId, RunAsAdministrator, this.ConfigurationName); connectionInfo.CreateContainerProcess(); remoteRunspace = CreateTemporaryRemoteRunspaceForPowerShellDirect(this.Host, connectionInfo); diff --git a/src/System.Management.Automation/engine/remoting/commands/ReceivePSSession.cs b/src/System.Management.Automation/engine/remoting/commands/ReceivePSSession.cs index 67477e5b36f..60e862e6011 100644 --- a/src/System.Management.Automation/engine/remoting/commands/ReceivePSSession.cs +++ b/src/System.Management.Automation/engine/remoting/commands/ReceivePSSession.cs @@ -566,7 +566,7 @@ private WSManConnectionInfo GetConnectionObject() ParameterSetName == ReceivePSSessionCommand.ComputerInstanceIdParameterSet) { // Create the WSManConnectionInfo object for the specified computer name. - string scheme = UseSSL.IsPresent ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; + string scheme = UseSSL ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; connectionInfo.Scheme = scheme; connectionInfo.ComputerName = ResolveComputerName(ComputerName); diff --git a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs index 05611d8c0ae..659e9419c1f 100644 --- a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs +++ b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs @@ -588,7 +588,7 @@ protected override void BeginProcessing() ThrowTerminatingError(errorRecord); } - if (RunAs32.IsPresent && Environment.Is64BitProcess) + if (RunAs32 && Environment.Is64BitProcess) { // We cannot start a 32-bit 'pwsh' process from a 64-bit 'pwsh' installation. string message = RemotingErrorIdStrings.RunAs32NotSupported; diff --git a/src/System.Management.Automation/engine/remoting/commands/WaitJob.cs b/src/System.Management.Automation/engine/remoting/commands/WaitJob.cs index 3bbc4463fe8..db5a0099e3c 100644 --- a/src/System.Management.Automation/engine/remoting/commands/WaitJob.cs +++ b/src/System.Management.Automation/engine/remoting/commands/WaitJob.cs @@ -165,7 +165,7 @@ private void HandleJobStateChangedEvent(object source, JobStateEventArgs eventAr Dbg.Assert(_blockedJobs.All(j => !_finishedJobs.Contains(j)), "Job cannot be in *both* _blockedJobs and _finishedJobs"); - if (this.Any.IsPresent) + if (this.Any) { if (_finishedJobs.Count > 0) { diff --git a/src/System.Management.Automation/engine/remoting/commands/getrunspacecommand.cs b/src/System.Management.Automation/engine/remoting/commands/getrunspacecommand.cs index fb6bf348aba..6aa2764ee23 100644 --- a/src/System.Management.Automation/engine/remoting/commands/getrunspacecommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/getrunspacecommand.cs @@ -453,7 +453,7 @@ private Collection GetConnectionObjects() if (ParameterSetName == GetPSSessionCommand.ComputerNameParameterSet || ParameterSetName == GetPSSessionCommand.ComputerInstanceIdParameterSet) { - string scheme = UseSSL.IsPresent ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; + string scheme = UseSSL ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; foreach (string computerName in ComputerName) { diff --git a/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs b/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs index 8986def5a6d..6aabed616ff 100644 --- a/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs @@ -798,7 +798,7 @@ private List CreateRunspacesWhenComputerNameParameterSpecified() { WSManConnectionInfo connectionInfo = null; connectionInfo = new WSManConnectionInfo(); - string scheme = UseSSL.IsPresent ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; + string scheme = UseSSL ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme; connectionInfo.ComputerName = resolvedComputerNames[i]; connectionInfo.Port = Port; connectionInfo.AppName = ApplicationName; @@ -1015,7 +1015,7 @@ private List CreateRunspacesWhenContainerParameterSpecified() // Hyper-V container uses Hype-V socket as transport. // Windows Server container uses named pipe as transport. // - connectionInfo = ContainerConnectionInfo.CreateContainerConnectionInfo(input, RunAsAdministrator.IsPresent, this.ConfigurationName); + connectionInfo = ContainerConnectionInfo.CreateContainerConnectionInfo(input, RunAsAdministrator, this.ConfigurationName); resolvedNameList.Add(connectionInfo.ComputerName); diff --git a/src/System.Management.Automation/help/UpdateHelpCommand.cs b/src/System.Management.Automation/help/UpdateHelpCommand.cs index 9df82699a32..c92dd353698 100644 --- a/src/System.Management.Automation/help/UpdateHelpCommand.cs +++ b/src/System.Management.Automation/help/UpdateHelpCommand.cs @@ -174,7 +174,7 @@ protected override void ProcessRecord() if (!_isInitialized) { - if (_path == null && Recurse.IsPresent) + if (_path == null && Recurse) { PSArgumentException e = new PSArgumentException(StringUtil.Format(HelpDisplayStrings.CannotSpecifyRecurseWithoutPath)); ThrowTerminatingError(e.ErrorRecord); diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 71de4e8ac67..787db592eab 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -6835,7 +6835,7 @@ public IContentWriter GetContentWriter(string path) #if !UNIX streamName = dynParams.Stream; #endif - suppressNewline = dynParams.NoNewline.IsPresent; + suppressNewline = dynParams.NoNewline; } } diff --git a/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs b/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs index 73bb24ccd08..aeb37f2eb09 100644 --- a/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs +++ b/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs @@ -61,12 +61,12 @@ protected override void EndProcessing() string message = $"Hello World {Name}."; if (ExperimentalFeature.IsEnabled("ExpTest.FeatureOne")) { - if (SwitchOne.IsPresent) + if (SwitchOne) { message += "-SwitchOne is on."; } - if (SwitchTwo.IsPresent) + if (SwitchTwo) { message += "-SwitchTwo is on."; } From d10a180883616429f76b1cc2c0552007950c8853 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:02:21 +0100 Subject: [PATCH 2/3] `ToBool()` -> operator --- .../commands/utility/NewGuidCommand.cs | 2 +- .../commands/utility/ShowCommand/ShowCommand.cs | 4 ++-- .../host/msh/StartTranscriptCmdlet.cs | 2 +- .../engine/LanguagePrimitives.cs | 4 ++-- .../engine/remoting/commands/CustomShellCommands.cs | 6 +++--- src/System.Management.Automation/help/HelpCommands.cs | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs index 0e466f86d3f..77bc0aa3a51 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs @@ -49,7 +49,7 @@ protected override void ProcessRecord() } else { - guid = Empty.ToBool() ? Guid.Empty : Guid.NewGuid(); + guid = Empty ? Guid.Empty : Guid.NewGuid(); } WriteObject(guid); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs index 60b05807d48..e146e91333e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs @@ -369,7 +369,7 @@ private bool CanProcessRecordForOneCommand() try { - _commandViewModelObj = _showCommandProxy.GetCommandViewModel(new ShowCommandCommandInfo(commandInfo), _noCommonParameter.ToBool(), _importedModules, this.Name.Contains('\\')); + _commandViewModelObj = _showCommandProxy.GetCommandViewModel(new ShowCommandCommandInfo(commandInfo), _noCommonParameter, _importedModules, this.Name.Contains('\\')); _showCommandProxy.ShowCommandWindow(_commandViewModelObj, _passThrough); } catch (TargetInvocationException ti) @@ -394,7 +394,7 @@ private bool CanProcessRecordForAllCommands() try { - _showCommandProxy.ShowAllModulesWindow(_importedModules, _commands, _noCommonParameter.ToBool(), _passThrough); + _showCommandProxy.ShowAllModulesWindow(_importedModules, _commands, _noCommonParameter, _passThrough); } catch (TargetInvocationException ti) { diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs index 99482488c94..793cddd1587 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs @@ -234,7 +234,7 @@ protected override void BeginProcessing() System.Management.Automation.Remoting.PSSenderInfo psSenderInfo = this.SessionState.PSVariable.GetValue("PSSenderInfo") as System.Management.Automation.Remoting.PSSenderInfo; - Host.UI.StartTranscribing(effectiveFilePath, psSenderInfo, IncludeInvocationHeader.ToBool(), UseMinimalHeader); + Host.UI.StartTranscribing(effectiveFilePath, psSenderInfo, IncludeInvocationHeader, UseMinimalHeader); // ch.StartTranscribing(effectiveFilePath, Append); diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 13d8f66e5e9..b9d124b401d 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -1005,7 +1005,7 @@ public static bool IsTrue(object obj) } if (objType == typeof(SwitchParameter)) - return ((SwitchParameter)obj).ToBool(); + return (SwitchParameter)obj; IList objectArray = obj as IList; if (objectArray != null) @@ -3305,7 +3305,7 @@ private static bool ConvertSwitchParameterToBool(object valueToConvert, TypeTable backupTable) { typeConversion.WriteLine("Converting SwitchParameter to boolean."); - return ((SwitchParameter)valueToConvert).ToBool(); + return (SwitchParameter)valueToConvert; } private static bool ConvertIListToBool(object valueToConvert, diff --git a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs index 1d88210e7b6..08a2f433ebc 100644 --- a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs +++ b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs @@ -581,7 +581,7 @@ protected override void ProcessRecord() args: new object[] { file, shellName, - ShowSecurityDescriptorUI.ToBool(), + ShowSecurityDescriptorUI, force, whatIf, confirm, @@ -3482,7 +3482,7 @@ protected override void ProcessRecord() force, sddl, isSddlSpecified, - ShowSecurityDescriptorUI.ToBool(), + ShowSecurityDescriptorUI, WSManNativeApi.ResourceURIPrefix + shellName, shellNotFoundErrorMsg, shellNotPowerShellMsg, @@ -3639,7 +3639,7 @@ Hashtable optionsTable if (isUseSharedProcessSpecified) { - optionsTable[UseSharedProcessToken] = UseSharedProcess.ToBool().ToString(); + optionsTable[UseSharedProcessToken] = UseSharedProcess.ToString(); } setOptionsSb.InvokeUsingCmdlet( diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index 3bed2a26820..1c410db97ef 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -90,7 +90,7 @@ public SwitchParameter Detailed { set { - if (value.ToBool()) + if (value) { _viewTokenToAdd = HelpView.DetailedView; } @@ -117,7 +117,7 @@ public SwitchParameter Full { set { - if (value.ToBool()) + if (value) { _viewTokenToAdd = HelpView.FullView; } @@ -143,7 +143,7 @@ public SwitchParameter Examples { set { - if (value.ToBool()) + if (value) { _viewTokenToAdd = HelpView.ExamplesView; } From fff7ae38b56b9eee5e8626665c329b8fa693475e Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:03:28 +0100 Subject: [PATCH 3/3] `_isPresent` -> `_value` --- .../engine/MshCmdlet.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs index bcb6b21b479..662e4f48faf 100644 --- a/src/System.Management.Automation/engine/MshCmdlet.cs +++ b/src/System.Management.Automation/engine/MshCmdlet.cs @@ -74,14 +74,15 @@ public interface IDynamicParameters /// public readonly struct SwitchParameter { - private readonly bool _isPresent; + private readonly bool _value; + /// /// Returns true if the parameter was specified on the command line, false otherwise. /// /// True if the parameter was specified, false otherwise public bool IsPresent { - get { return _isPresent; } + get { return _value; } } /// /// Implicit cast operator for casting SwitchParameter to bool. @@ -90,7 +91,7 @@ public bool IsPresent /// The corresponding boolean value. public static implicit operator bool(SwitchParameter switchParameter) { - return switchParameter._isPresent; + return switchParameter._value; } /// @@ -109,7 +110,7 @@ public static implicit operator SwitchParameter(bool value) /// The boolean equivalent of the SwitchParameter. public bool ToBool() { - return _isPresent; + return _value; } /// @@ -120,7 +121,7 @@ public bool ToBool() /// public SwitchParameter(bool isPresent) { - _isPresent = isPresent; + _value = isPresent; } /// @@ -141,11 +142,11 @@ public override bool Equals(object obj) { if (obj is bool) { - return _isPresent == (bool)obj; + return _value == (bool)obj; } else if (obj is SwitchParameter) { - return _isPresent == (SwitchParameter)obj; + return _value == (SwitchParameter)obj; } else { @@ -158,7 +159,7 @@ public override bool Equals(object obj) /// The hash code for this cobject. public override int GetHashCode() { - return _isPresent.GetHashCode(); + return _value.GetHashCode(); } /// @@ -228,7 +229,7 @@ public override int GetHashCode() /// The string for this object. public override string ToString() { - return _isPresent.ToString(); + return _value.ToString(); } }