다음을 통해 공유


SessionStateKeeper Class

Definition

Every Runspace in one process contains SessionStateInternal per module (module SessionState). Every RuntimeType is associated to only one SessionState in the Runspace, which creates it: it's either global state or a module state. In the former case, module can be imported from the different runspaces in the same process. And so runspaces will share RuntimeType. But in every runspace, Type is associated with just one SessionState. We want type methods to be able access $script: variables and module-specific methods. To achieve it, we preserve reference to SessionState that creates type in the private field 'SessionStateFieldName'. Later, we use it to call scriptBlocks captured in ScriptBlockMemberMethodWrapper with the right sessionState.

public ref class SessionStateKeeper
public class SessionStateKeeper
type SessionStateKeeper = class
Public Class SessionStateKeeper
Inheritance
SessionStateKeeper

Methods

GetSessionState()

This method should be called only from

  • generated ctors for PowerShell classes, AND
  • ScriptBlockMemberMethodWrapper when invoking static methods of PowerShell classes. It's not intended to be a public API, but because we generate type in a different assembly it has to be public. Return type should be SessionStateInternal, but it violates accessibility consistency, so we use object.

Applies to