Example #1
0
        /// <summary>
        /// Adds columns to the output window.
        /// </summary>
        /// <param name="propertyNames">An array of property names to add.</param>
        /// <param name="displayNames">An array of display names to add.</param>
        /// <param name="types">An array of types to add.</param>
        internal void AddColumns(string[] propertyNames, string[] displayNames, Type[] types)
        {
            if (propertyNames is null)
            {
                throw new ArgumentNullException(nameof(propertyNames));
            }

            if (displayNames is null)
            {
                throw new ArgumentNullException(nameof(displayNames));
            }

            if (types is null)
            {
                throw new ArgumentNullException(nameof(types));
            }

            try
            {
                _graphicalHostReflectionWrapper.CallMethod("AddColumns", propertyNames, displayNames, types);
            }
            catch (TargetInvocationException ex)
            {
                // Verify if this is an error loading the System.Core dll.
                FileNotFoundException fileNotFoundEx = ex.InnerException as FileNotFoundException;
                if (fileNotFoundEx != null && fileNotFoundEx.FileName.Contains("System.Core"))
                {
                    _parentCmdlet.ThrowTerminatingError(
                        new ErrorRecord(new InvalidOperationException(
                                            StringUtil.Format(FormatAndOut_out_gridview.RestartPowerShell,
                                                              _parentCmdlet.CommandInfo.Name), ex.InnerException),
                                        "ErrorLoadingAssembly",
                                        ErrorCategory.ObjectNotFound,
                                        null));
                }
                else
                {
                    // Let PowerShell take care of this problem.
                    throw;
                }
            }
        }