internal PSVariable GetVariableItem(VariablePath variablePath, out SessionStateScope scope, CommandOrigin origin) { scope = null; if (variablePath == null) { throw PSTraceSource.NewArgumentNullException("variablePath"); } VariableScopeItemSearcher searcher = new VariableScopeItemSearcher(this, variablePath, origin); PSVariable current = null; if (searcher.MoveNext()) { current = (PSVariable)searcher.Current; scope = searcher.CurrentLookupScope; } return current; }
} // GetVariableFromProvider #pragma warning restore 0162 /// <summary> /// Looks up the specified variable and returns the context under which /// the variable was found as well as the variable itself. /// </summary> /// /// <param name="variablePath"> /// The VariablePath helper for the variable. /// </param> /// /// <param name="scope"> /// The scope the variable was found in. Null if the variable wasn't found. /// </param> /// /// <param name="origin"> /// Origin of the command requesting this variable /// </param> /// /// <returns> /// The variable if it was found or null if it was not. /// </returns> /// /// <remarks> /// The <paramref name="variablePath" /> is first parsed to see if it contains a drive /// specifier or special scope. If a special scope is found ("LOCAL" or "GLOBAL") /// then only that scope is searched for the variable. /// - current scope /// - each consecutive parent scope until the variable is found. /// - global scope /// </remarks> /// /// <exception cref="ArgumentNullException"> /// If <paramref name="variablePath"/> is null. /// </exception> /// internal PSVariable GetVariableItem( VariablePath variablePath, out SessionStateScope scope, CommandOrigin origin) { scope = null; if (variablePath == null) { throw PSTraceSource.NewArgumentNullException("variablePath"); } Dbg.Diagnostics.Assert(variablePath.IsVariable, "Can't get variable w/ non-variable path"); VariableScopeItemSearcher searcher = new VariableScopeItemSearcher(this, variablePath, origin); PSVariable result = null; if (searcher.MoveNext()) { result = ((IEnumerator<PSVariable>)searcher).Current; scope = searcher.CurrentLookupScope; } return result; } // GetVariableItem