Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,16 +1009,15 @@ internal void SetVariableValue(string name, object newValue)
/// The origin of the caller of this API
/// </param>
/// <returns>
/// A PSVariable object if <paramref name="variablePath"/> refers to a variable.
/// An PSObject if <paramref name="variablePath"/> refers to a provider path.
/// The resulting <see cref="PSVariable"/> for <paramref name="variable"/>, or null.
/// </returns>
/// <exception cref="ArgumentNullException">
/// If <paramref name="variable"/> is null.
/// </exception>
/// <exception cref="SessionStateUnauthorizedAccessException">
/// If the variable is read-only or constant.
/// </exception>
internal object SetVariable(PSVariable variable, bool force, CommandOrigin origin)
internal PSVariable SetVariable(PSVariable variable, bool force, CommandOrigin origin)
{
Comment thread
xtqqczze marked this conversation as resolved.
if (variable == null || string.IsNullOrEmpty(variable.Name))
{
Expand Down Expand Up @@ -1098,8 +1097,7 @@ internal object SetVariable(
/// The origin of the caller
/// </param>
/// <returns>
/// A PSVariable object if <paramref name="variablePath"/> refers to a variable.
/// An PSObject if <paramref name="variablePath"/> refers to a provider path.
/// The resulting <see cref="PSVariable"/> for <paramref name="variablePath"/>, or null.
/// </returns>
/// <exception cref="ArgumentNullException">
/// If <paramref name="variablePath"/> is null.
Expand All @@ -1120,14 +1118,14 @@ internal object SetVariable(
/// <exception cref="ProviderInvocationException">
/// If the provider threw an exception.
/// </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));
Expand Down Expand Up @@ -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<IContentWriter> writers = null;
Expand Down Expand Up @@ -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<PSObject> setItemResult =
SetItem (variablePath.LookupPath.ToString (), newValue);

if (setItemResult != null &&
setItemResult.Count > 0)
{
result = setItemResult[0];
}
}
#endif
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading