internal static object GetVariableValue(VariablePath variablePath, ExecutionContext executionContext, VariableExpressionAst varAst) { if (!variablePath.IsVariable) { CmdletProviderContext contextOut; SessionStateScope scopeOut; SessionStateInternal ss = executionContext.EngineSessionState; return(ss.GetVariableValueFromProvider(variablePath, out contextOut, out scopeOut, ss.CurrentScope.ScopeOrigin)); } SessionStateInternal sessionState = executionContext.EngineSessionState; CommandOrigin origin = sessionState.CurrentScope.ScopeOrigin; SessionStateScope scope; PSVariable var = sessionState.GetVariableItem(variablePath, out scope, origin); if (var != null) { return(var.Value); } if (sessionState.ExecutionContext._debuggingMode > 0) { sessionState.ExecutionContext.Debugger.CheckVariableRead(variablePath.UnqualifiedPath); } if (ThrowStrictModeUndefinedVariable(executionContext, varAst)) { throw InterpreterError.NewInterpreterException(variablePath.UserPath, typeof(RuntimeException), varAst.Extent, "VariableIsUndefined", ParserStrings.VariableIsUndefined, variablePath.UserPath); } return(null); }
private object PrivateGetValue(ExecutionContext context) { try { if (this._useConstantValue) { return(this._constantValue); } if (!this._variablePath.IsScopedItem) { CmdletProviderContext context1 = (CmdletProviderContext)null; SessionStateScope scope = (SessionStateScope)null; SessionStateInternal engineSessionState = context.EngineSessionState; return(engineSessionState.GetVariableValueFromProvider(this._variablePath, out context1, out scope, engineSessionState.currentScope.ScopeOrigin)); } PSVariable variable = this.GetVariable(context); if (this._typeConstraint != null && this._typeConstraint.Count == 1 && this._typeConstraint[0].Type.Equals(typeof(PSReference))) { return(variable != null ? (object)new PSReference((object)variable) : throw InterpreterError.NewInterpreterException((object)this.NodeToken, typeof(RuntimeException), this.NodeToken, "NonExistingVariableReference", (object)this.NodeToken)); } if (variable != null) { return(variable.Value); } if (context.Debugger.IsOn) { context.Debugger.CheckVariableRead(this._varName); } return((object)null); } catch (RuntimeException ex) { if (ex.ErrorRecord != null && ex.ErrorRecord.InvocationInfo == null) { ex.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this.NodeToken, context)); } throw; } }