public PSModuleInfo(ScriptBlock scriptBlock) { this._context = LocalPipeline.GetExecutionContextFromTLS(); if (this._context == null) { throw new InvalidOperationException(nameof(PSModuleInfo)); } PSModuleInfo.SetDefaultDynamicNameAndPath(this); this._sessionState = new SessionState(this._context.EngineSessionState, true, true); this._sessionState.Internal.Module = this; SessionStateInternal engineSessionState = this._context.EngineSessionState; try { ArrayList resultList = (ArrayList)null; this._context.EngineSessionState = this._sessionState.Internal; this._context.EngineSessionState.SetVariableValue("PSScriptRoot", (object)this._path); scriptBlock = scriptBlock.Clone(true); scriptBlock.SessionState = this._sessionState; if (scriptBlock == null) { throw PSModuleInfo.tracer.NewInvalidOperationException(); } scriptBlock.InvokeWithPipe(false, true, (object)AutomationNull.Value, (object)AutomationNull.Value, (object)AutomationNull.Value, (Pipe)null, ref resultList); } finally { this._context.EngineSessionState = engineSessionState; } }
public PSModuleInfo(bool linkToGlobal) { this._context = LocalPipeline.GetExecutionContextFromTLS(); if (this._context == null) { throw new InvalidOperationException(nameof(PSModuleInfo)); } PSModuleInfo.SetDefaultDynamicNameAndPath(this); this._sessionState = new SessionState(this._context.EngineSessionState, true, linkToGlobal); this._sessionState.Internal.Module = this; }