diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index e674cb1c5eb..e09ecfa25b4 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -996,7 +996,7 @@ internal void SetupPipelineVariable() // Create the pipeline variable _pipelineVarReference = new PSVariable(PipelineVariable); - object varToUse = _state.Internal.SetVariable( + PSVariable varToUse = _state.Internal.SetVariable( _pipelineVarReference, force: false, CommandOrigin.Internal); @@ -1011,7 +1011,7 @@ internal void SetupPipelineVariable() { // A variable with the same name already exists in the same scope and it was returned. // In this case, we update the reference and don't remove the variable in the end. - _pipelineVarReference = (PSVariable)varToUse; + _pipelineVarReference = varToUse; } if (_thisCommand is not PSScriptCmdlet) diff --git a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs index 336c2b77952..9ef3ff59154 100644 --- a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs @@ -1009,8 +1009,7 @@ internal void SetVariableValue(string name, object newValue) /// The origin of the caller of this API /// /// - /// A PSVariable object if refers to a variable. - /// An PSObject if refers to a provider path. + /// The resulting for , or null. /// /// /// If is null. @@ -1018,7 +1017,7 @@ internal void SetVariableValue(string name, object newValue) /// /// If the variable is read-only or constant. /// - internal object SetVariable(PSVariable variable, bool force, CommandOrigin origin) + internal PSVariable SetVariable(PSVariable variable, bool force, CommandOrigin origin) { if (variable == null || string.IsNullOrEmpty(variable.Name)) { @@ -1098,8 +1097,7 @@ internal object SetVariable( /// The origin of the caller /// /// - /// A PSVariable object if refers to a variable. - /// An PSObject if refers to a provider path. + /// The resulting for , or null. /// /// /// If is null. @@ -1120,14 +1118,14 @@ internal object SetVariable( /// /// If the provider threw an exception. /// - internal object SetVariable( + internal PSVariable SetVariable( VariablePath variablePath, object newValue, bool asValue, bool force, CommandOrigin origin) { - object result = null; + PSVariable result = null; if (variablePath == null) { throw PSTraceSource.NewArgumentNullException(nameof(variablePath)); @@ -1184,7 +1182,7 @@ internal object SetVariable( // There is probably a more efficient way to do this. GetVariableValue(variablePath, out context, out scope); -#if true + // PSVariable get/set is the get/set of content in the provider Collection writers = null; @@ -1330,26 +1328,6 @@ internal object SetVariable( { writer.Close(); } -#else - if (context != null) - { - context.Force = force; - SetItem (variablePath.LookupPath.ToString (), newValue, context); - - context.ThrowFirstErrorOrDoNothing(true); - } - else - { - Collection setItemResult = - SetItem (variablePath.LookupPath.ToString (), newValue); - - if (setItemResult != null && - setItemResult.Count > 0) - { - result = setItemResult[0]; - } - } -#endif } return result; diff --git a/src/System.Management.Automation/namespaces/VariableProvider.cs b/src/System.Management.Automation/namespaces/VariableProvider.cs index 5f9934d326c..69a309b5d2a 100644 --- a/src/System.Management.Automation/namespaces/VariableProvider.cs +++ b/src/System.Management.Automation/namespaces/VariableProvider.cs @@ -132,7 +132,7 @@ internal override void SetSessionStateItem(string name, object value, bool write variable = new PSVariable(name, null); } - PSVariable item = SessionState.Internal.SetVariable(variable, Force, Context.Origin) as PSVariable; + PSVariable item = SessionState.Internal.SetVariable(variable, Force, Context.Origin); if (writeItem && item != null) {