From 7d6b6d8bf30318d5bb733eadce5cbe7af6ee032a Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 8 May 2025 00:10:05 +0500 Subject: [PATCH] Add internal methods to check Preferences (#25514) --- .../engine/MshCommandRuntime.cs | 15 +++++++++++++++ src/System.Management.Automation/engine/cmdlet.cs | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index 9d59d02cb3..883c800dea 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -390,6 +390,9 @@ namespace System.Management.Automation WriteProgress(sourceId, progressRecord, false); } + internal bool IsWriteProgressEnabled() + => WriteHelper_ShouldWrite(ProgressPreference, lastProgressContinueStatus); + internal void WriteProgress( Int64 sourceId, ProgressRecord progressRecord, @@ -472,6 +475,9 @@ namespace System.Management.Automation WriteDebug(new DebugRecord(text)); } + internal bool IsWriteDebugEnabled() + => WriteHelper_ShouldWrite(DebugPreference, lastDebugContinueStatus); + /// /// Display debug information. /// @@ -566,6 +572,9 @@ namespace System.Management.Automation WriteVerbose(new VerboseRecord(text)); } + internal bool IsWriteVerboseEnabled() + => WriteHelper_ShouldWrite(VerbosePreference, lastVerboseContinueStatus); + /// /// Display verbose information. /// @@ -660,6 +669,9 @@ namespace System.Management.Automation WriteWarning(new WarningRecord(text)); } + internal bool IsWriteWarningEnabled() + => WriteHelper_ShouldWrite(WarningPreference, lastWarningContinueStatus); + /// /// Display warning information. /// @@ -733,6 +745,9 @@ namespace System.Management.Automation WriteInformation(informationRecord, false); } + internal bool IsWriteInformationEnabled() + => WriteHelper_ShouldWrite(InformationPreference, lastInformationContinueStatus); + /// /// Display tagged object information. /// diff --git a/src/System.Management.Automation/engine/cmdlet.cs b/src/System.Management.Automation/engine/cmdlet.cs index ffe13b7304..db2233d44a 100644 --- a/src/System.Management.Automation/engine/cmdlet.cs +++ b/src/System.Management.Automation/engine/cmdlet.cs @@ -458,6 +458,9 @@ namespace System.Management.Automation } } + internal bool IsWriteVerboseEnabled() + => commandRuntime is not MshCommandRuntime mshRuntime || mshRuntime.IsWriteVerboseEnabled(); + /// /// Display warning information. /// @@ -495,6 +498,9 @@ namespace System.Management.Automation } } + internal bool IsWriteWarningEnabled() + => commandRuntime is not MshCommandRuntime mshRuntime || mshRuntime.IsWriteWarningEnabled(); + /// /// Write text into pipeline execution log. /// @@ -603,6 +609,9 @@ namespace System.Management.Automation throw new System.NotImplementedException("WriteProgress"); } + internal bool IsWriteProgressEnabled() + => commandRuntime is not MshCommandRuntime mshRuntime || mshRuntime.IsWriteProgressEnabled(); + /// /// Display debug information. /// @@ -646,6 +655,9 @@ namespace System.Management.Automation } } + internal bool IsWriteDebugEnabled() + => commandRuntime is not MshCommandRuntime mshRuntime || mshRuntime.IsWriteDebugEnabled(); + /// /// Route information to the user or host. /// @@ -753,6 +765,9 @@ namespace System.Management.Automation } } + internal bool IsWriteInformationEnabled() + => commandRuntime is not MshCommandRuntime mshRuntime || mshRuntime.IsWriteInformationEnabled(); + #endregion Write #region ShouldProcess