public PsContextHelper(ScriptBlock scriptBlock, PsContext withContext, bool saveContext) { if (null == scriptBlock) { throw new ArgumentNullException("scriptBlock"); } m_withContext = withContext; if (!saveContext) { m_scriptBlock = scriptBlock; return; } if (null == m_withContext) { m_withContext = new PsContext(); } m_savedContext = new PSVariable(c_SavedContextVarName, null); m_withContext.Vars[m_savedContext.Name] = m_savedContext; m_ctxMarker = DbgProvider.SetContextStartMarker(); // Hacking the scriptBlock and smuggling the context out like this is // pretty ugly. I don't know a better way, though--I'm open to // suggestions. m_scriptBlock = ScriptBlock.Create(Util.Sprintf(@"{0} . ""{1}\\GetPsContextFunc.ps1"" ${2} = Get-PsContext", scriptBlock.ToString(), DbgProvider.PsScriptRoot, c_SavedContextVarName)); } // end constructor