// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Management.Automation.Host; using Dbg = System.Management.Automation; namespace System.Management.Automation { /// /// Exposes the Engine APIs for a particular instance of the engine. /// public class EngineIntrinsics { #region Constructors /// /// Hide the default constructor since we always require an instance of ExecutionContext. /// private EngineIntrinsics() { Dbg.Diagnostics.Assert( false, "This constructor should never be called. Only the constructor that takes an instance of ExecutionContext should be called."); } /// /// The internal constructor for this object. It should be the only one that gets called. /// /// /// An instance of ExecutionContext that the APIs should work against. /// /// /// If is null. /// internal EngineIntrinsics(ExecutionContext context) { ArgumentNullException.ThrowIfNull(context); _context = context; _host = context.EngineHostInterface; } #endregion Constructors #region Public methods /// /// Gets engine APIs to access the host. /// public PSHost Host { get { Dbg.Diagnostics.Assert( _host != null, "The only constructor for this class should always set the host field"); return _host; } } /// /// Gets engine APIs to access the event manager. /// public PSEventManager Events { get { return _context.Events; } } /// /// Gets the engine APIs to access providers. /// public ProviderIntrinsics InvokeProvider { get { return _context.EngineSessionState.InvokeProvider; } } /// /// Gets the engine APIs to access session state. /// public SessionState SessionState { get { return _context.EngineSessionState.PublicSessionState; } } /// /// Gets the engine APIs to invoke a command. /// public CommandInvocationIntrinsics InvokeCommand { get { return _invokeCommand ??= new CommandInvocationIntrinsics(_context); } } #endregion Public methods #region private data private readonly ExecutionContext _context; private readonly PSHost _host; private CommandInvocationIntrinsics _invokeCommand; #endregion private data } }