PowerShellHtmlConsole.PSWrapper.ReportException C# (CSharp) Метод

ReportException() приватный Метод

To display an exception using the display formatter, run a second pipeline passing in the error record. The runtime will bind this to the $input variable, which is why $input is being piped to the Out-String cmdlet. The WriteErrorLine method is called to make sure the error gets displayed in the correct error color.
private ReportException ( Exception e ) : void
e System.Exception The exception to display.
Результат void
        private void ReportException(Exception e)
        {
            if (e == null)
            {
                return;
            }
            var icer = e as IContainsErrorRecord;
            object error = icer != null
                               ? icer.ErrorRecord
                               : new ErrorRecord(e, "Host.ReportException", ErrorCategory.NotSpecified, null);

            using (var powerShell = PowerShell.Create())
            {
                powerShell.Runspace = _runspace;
                powerShell.AddScript("$input").AddCommand("out-string");

                // Do not merge errors, this function will swallow errors.
                var inputCollection = new PSDataCollection<object> {error};
                inputCollection.Complete();
                var result = powerShell.Invoke(inputCollection);

                if (result.Count > 0)
                {
                    var str = result[0].BaseObject as string;
                    if (!string.IsNullOrEmpty(str))
                    {
                        // Remove \r\n, which is added by the Out-String cmdlet.
                        _psRemoteHost.UI.WriteErrorLine(str.Substring(0, str.Length - 2));
                    }
                }
            }
        }