Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
HelpCategoryInvalidException.cs127 linesDownload Raw Back to help
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4#pragma warning disable 1634, 16915#pragma warning disable 565066 7using System;8using System.Management.Automation;9using System.Runtime.Serialization;10using System.Reflection;11using System.Security.Permissions;12 13namespace Microsoft.PowerShell.Commands14{15    /// <summary>16    /// The exception that is thrown when there is no help category matching17    /// a specific input string.18    /// </summary>19    public class HelpCategoryInvalidException : ArgumentException, IContainsErrorRecord20    {21        /// <summary>22        /// Initializes a new instance of the HelpCategoryInvalidException class.23        /// </summary>24        /// <param name="helpCategory">The name of help category that is invalid.</param>25        public HelpCategoryInvalidException(string helpCategory)26            : base()27        {28            _helpCategory = helpCategory;29            CreateErrorRecord();30        }31 32        /// <summary>33        /// Initializes a new instance of the HelpCategoryInvalidException class.34        /// </summary>35        public HelpCategoryInvalidException()36            : base()37        {38            CreateErrorRecord();39        }40 41        /// <summary>42        /// Initializes a new instance of the HelpCategoryInvalidException class.43        /// </summary>44        /// <param name="helpCategory">The name of help category that is invalid.</param>45        /// <param name="innerException">The inner exception of this exception.</param>46        public HelpCategoryInvalidException(string helpCategory, Exception innerException)47            : base(48                  (innerException != null) ? innerException.Message : string.Empty,49                  innerException)50        {51            _helpCategory = helpCategory;52            CreateErrorRecord();53        }54 55        /// <summary>56        /// Creates an internal error record based on helpCategory.57        /// </summary>58        private void CreateErrorRecord()59        {60            _errorRecord = new ErrorRecord(new ParentContainsErrorRecordException(this), "HelpCategoryInvalid", ErrorCategory.InvalidArgument, null);61            _errorRecord.ErrorDetails = new ErrorDetails(typeof(HelpCategoryInvalidException).Assembly, "HelpErrors", "HelpCategoryInvalid", _helpCategory);62        }63 64        private ErrorRecord _errorRecord;65 66        /// <summary>67        /// Gets ErrorRecord embedded in this exception.68        /// </summary>69        /// <value>ErrorRecord instance</value>70        public ErrorRecord ErrorRecord71        {72            get73            {74                return _errorRecord;75            }76        }77 78        private readonly string _helpCategory = System.Management.Automation.HelpCategory.None.ToString();79 80        /// <summary>81        /// Gets name of the help category that is invalid.82        /// </summary>83        /// <value>Name of the help category.</value>84        public string HelpCategory85        {86            get87            {88                return _helpCategory;89            }90        }91 92        /// <summary>93        /// Gets exception message for this exception.94        /// </summary>95        /// <value>Error message.</value>96        public override string Message97        {98            get99            {100                if (_errorRecord != null)101                {102                    return _errorRecord.ToString();103                }104 105                return base.Message;106            }107        }108 109        #region Serialization110        /// <summary>111        /// Initializes a new instance of the HelpCategoryInvalidException class.112        /// </summary>113        /// <param name="info">Serialization information.</param>114        /// <param name="context">Streaming context.</param>115        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")] 116        protected HelpCategoryInvalidException(SerializationInfo info,117                                        StreamingContext context)            118        {119            throw new NotSupportedException();120        }121 122        #endregion Serialization123    }124}125 126#pragma warning restore 56506127