Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
MshInvalidOperationException.cs123 linesDownload Raw Back to utils
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Runtime.Serialization;5 6namespace System.Management.Automation7{8    /// <summary>9    /// This is a wrapper for exception class10    /// <see cref="System.InvalidOperationException"/>11    /// which provides additional information via12    /// <see cref="System.Management.Automation.IContainsErrorRecord"/>.13    /// </summary>14    /// <remarks>15    /// Instances of this exception class are usually generated by the16    /// PowerShell Engine.  It is unusual for code outside the PowerShell Engine17    /// to create an instance of this class.18    /// </remarks>19    public class PSInvalidOperationException20            : InvalidOperationException, IContainsErrorRecord21    {22        #region ctor23        /// <summary>24        /// Initializes a new instance of the PSInvalidOperationException class.25        /// </summary>26        /// <returns>Constructed object.</returns>27        public PSInvalidOperationException()28            : base()29        {30        }31 32        #region Serialization33        /// <summary>34        /// Initializes a new instance of the PSInvalidOperationException class35        /// using data serialized via36        /// <see cref="System.Runtime.Serialization.ISerializable"/>37        /// </summary>38        /// <param name="info">Serialization information.</param>39        /// <param name="context">Streaming context.</param>40        /// <returns>Constructed object.</returns>41        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]42        protected PSInvalidOperationException(SerializationInfo info,43                           StreamingContext context)44        {45            throw new NotSupportedException();46        }47        #endregion Serialization48 49        /// <summary>50        /// Initializes a new instance of the PSInvalidOperationException class.51        /// </summary>52        /// <param name="message"></param>53        /// <returns>Constructed object.</returns>54        public PSInvalidOperationException(string message)55            : base(message)56        {57        }58 59        /// <summary>60        /// Initializes a new instance of the PSInvalidOperationException class.61        /// </summary>62        /// <param name="message"></param>63        /// <param name="innerException"></param>64        /// <returns>Constructed object.</returns>65        public PSInvalidOperationException(string message,66                                            Exception innerException)67                : base(message, innerException)68        {69        }70 71        /// <summary>72        /// Initializes a new instance of the PSInvalidOperationException class.73        /// </summary>74        /// <param name="message"></param>75        /// <param name="innerException"></param>76        /// <param name="errorId"></param>77        /// <param name="errorCategory"></param>78        /// <param name="target"></param>79        /// <returns>Constructed object.</returns>80        internal PSInvalidOperationException(string message, Exception innerException, string errorId, ErrorCategory errorCategory, object target)81            : base(message, innerException)82        {83            _errorId = errorId;84            _errorCategory = errorCategory;85            _target = target;86        }87        #endregion ctor88 89        /// <summary>90        /// Additional information about the error.91        /// </summary>92        /// <value></value>93        /// <remarks>94        /// Note that ErrorRecord.Exception is95        /// <see cref="System.Management.Automation.ParentContainsErrorRecordException"/>.96        /// </remarks>97        public ErrorRecord ErrorRecord98        {99            get100            {101                _errorRecord ??= new ErrorRecord(102                    new ParentContainsErrorRecordException(this),103                    _errorId,104                    _errorCategory,105                    _target);106 107                return _errorRecord;108            }109        }110 111        private ErrorRecord _errorRecord;112        private string _errorId = "InvalidOperation";113 114        internal void SetErrorId(string errorId)115        {116            _errorId = errorId;117        }118 119        private readonly ErrorCategory _errorCategory = ErrorCategory.InvalidOperation;120        private readonly object _target = null;121    }122}123