private static object GetUsingValue(MutableTuple tuple, int index, ExecutionContext context) { UsingResult usingValueFromTuple = GetUsingValueFromTuple(tuple, index); if (usingValueFromTuple != null) { return(usingValueFromTuple.Value); } for (SessionStateScope scope = context.EngineSessionState.CurrentScope; scope != null; scope = scope.Parent) { usingValueFromTuple = GetUsingValueFromTuple(scope.LocalsTuple, index); if (usingValueFromTuple != null) { return(usingValueFromTuple.Value); } foreach (MutableTuple tuple2 in scope.DottedScopes) { usingValueFromTuple = GetUsingValueFromTuple(tuple2, index); if (usingValueFromTuple != null) { return(usingValueFromTuple.Value); } } } throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "UsingWithoutInvokeCommand", ParserStrings.UsingWithoutInvokeCommand, new object[0]); }
internal static object GetUsingValue(MutableTuple tuple, string usingExpressionKey, int index, ExecutionContext context) { UsingResult result = GetUsingValueFromTuple(tuple, usingExpressionKey, index); if (result != null) { return(result.Value); } var scope = context.EngineSessionState.CurrentScope; while (scope != null) { result = GetUsingValueFromTuple(scope.LocalsTuple, usingExpressionKey, index); if (result != null) { return(result.Value); } foreach (var dottedScope in scope.DottedScopes) { result = GetUsingValueFromTuple(dottedScope, usingExpressionKey, index); if (result != null) { return(result.Value); } } scope = scope.Parent; } // $PSBoundParameters is null or not the expected type (because someone may have assigned to it), so // we can't even guess if they were mis-using $using:foo throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "UsingWithoutInvokeCommand", ParserStrings.UsingWithoutInvokeCommand); }