Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
ExtendedTypeSystemException.cs642 linesDownload Raw Back to engine
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Management.Automation.Internal;5using System.Runtime.Serialization;6using System.Security.Permissions;7 8namespace System.Management.Automation9{10    /// <summary>11    /// Defines the exception thrown for all Extended type system related errors.12    /// </summary>13    public class ExtendedTypeSystemException : RuntimeException14    {15        #region ctor16        /// <summary>17        /// Initializes a new instance of ExtendedTypeSystemException with the message set18        /// to typeof(ExtendedTypeSystemException).FullName.19        /// </summary>20        public ExtendedTypeSystemException()21            : base(typeof(ExtendedTypeSystemException).FullName)22        {23        }24 25        /// <summary>26        /// Initializes a new instance of ExtendedTypeSystemException setting the message.27        /// </summary>28        /// <param name="message">The exception's message.</param>29        public ExtendedTypeSystemException(string message)30            : base(message)31        {32        }33 34        /// <summary>35        /// Initializes a new instance of ExtendedTypeSystemException setting the message and innerException.36        /// </summary>37        /// <param name="message">The exception's message.</param>38        /// <param name="innerException">The exception's inner exception.</param>39        public ExtendedTypeSystemException(string message, Exception innerException)40            : base(message, innerException)41        {42        }43 44        /// <summary>45        /// Recommended constructor for the class.46        /// </summary>47        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>48        /// <param name="innerException">The inner exception, null for none.</param>49        /// <param name="resourceString">Resource string.</param>50        /// <param name="arguments">Arguments to the resource string.</param>51        internal ExtendedTypeSystemException(52            string errorId,53            Exception innerException,54            string resourceString,55            params object[] arguments)56            : base(57                  StringUtil.Format(resourceString, arguments),58                  innerException)59        {60            SetErrorId(errorId);61        }62 63        #region Serialization64        /// <summary>65        /// Initializes a new instance of ExtendedTypeSystemException with serialization parameters.66        /// </summary>67        /// <param name="info">Serialization information.</param>68        /// <param name="context">Streaming context.</param>69        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]70        protected ExtendedTypeSystemException(SerializationInfo info, StreamingContext context)71            : base(info, context)72        {73        }74        #endregion Serialization75 76        #endregion ctor77 78    }79 80    /// <summary>81    /// Defines the exception thrown for Method related errors.82    /// </summary>83    public class MethodException : ExtendedTypeSystemException84    {85        internal const string MethodArgumentCountExceptionMsg = "MethodArgumentCountException";86        internal const string MethodAmbiguousExceptionMsg = "MethodAmbiguousException";87        internal const string MethodArgumentConversionExceptionMsg = "MethodArgumentConversionException";88        internal const string NonRefArgumentToRefParameterMsg = "NonRefArgumentToRefParameter";89        internal const string RefArgumentToNonRefParameterMsg = "RefArgumentToNonRefParameter";90 91        #region ctor92        /// <summary>93        /// Initializes a new instance of MethodException with the message set94        /// to typeof(MethodException).FullName.95        /// </summary>96        public MethodException()97            : base(typeof(MethodException).FullName)98        {99        }100 101        /// <summary>102        /// Initializes a new instance of MethodException setting the message.103        /// </summary>104        /// <param name="message">The exception's message.</param>105        public MethodException(string message)106            : base(message)107        {108        }109 110        /// <summary>111        /// Initializes a new instance of MethodException setting the message and innerException.112        /// </summary>113        /// <param name="message">The exception's message.</param>114        /// <param name="innerException">The exception's inner exception.</param>115        public MethodException(string message, Exception innerException)116            : base(message, innerException)117        {118        }119 120        /// <summary>121        /// Recommended constructor for the class.122        /// </summary>123        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>124        /// <param name="innerException">The inner exception.</param>125        /// <param name="resourceString">Resource string.</param>126        /// <param name="arguments">Arguments to the resource string.</param>127        internal MethodException(128            string errorId,129            Exception innerException,130            string resourceString,131            params object[] arguments)132            : base(errorId, innerException, resourceString, arguments)133        {134        }135 136        #region Serialization137        /// <summary>138        /// Initializes a new instance of MethodException with serialization parameters.139        /// </summary>140        /// <param name="info">Serialization information.</param>141        /// <param name="context">Streaming context.</param>142        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]143        protected MethodException(SerializationInfo info, StreamingContext context)144        {145            throw new NotSupportedException();146        }147        #endregion Serialization148 149        #endregion ctor150 151    }152 153    /// <summary>154    /// Defines the exception thrown for Method invocation exceptions.155    /// </summary>156    public class MethodInvocationException : MethodException157    {158        internal const string MethodInvocationExceptionMsg = "MethodInvocationException";159        internal const string CopyToInvocationExceptionMsg = "CopyToInvocationException";160        internal const string WMIMethodInvocationException = "WMIMethodInvocationException";161 162        #region ctor163        /// <summary>164        /// Initializes a new instance of MethodInvocationException with the message set165        /// to typeof(MethodInvocationException).FullName.166        /// </summary>167        public MethodInvocationException()168            : base(typeof(MethodInvocationException).FullName)169        {170        }171 172        /// <summary>173        /// Initializes a new instance of MethodInvocationException setting the message.174        /// </summary>175        /// <param name="message">The exception's message.</param>176        public MethodInvocationException(string message)177            : base(message)178        {179        }180 181        /// <summary>182        /// Initializes a new instance of MethodInvocationException setting the message and innerException.183        /// </summary>184        /// <param name="message">The exception's message.</param>185        /// <param name="innerException">The exception's inner exception.</param>186        public MethodInvocationException(string message, Exception innerException)187            : base(message, innerException)188        {189        }190 191        /// <summary>192        /// Recommended constructor for the class.193        /// </summary>194        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>195        /// <param name="innerException">The inner exception.</param>196        /// <param name="resourceString">Resource string.</param>197        /// <param name="arguments">Arguments to the resource string.</param>198        internal MethodInvocationException(199            string errorId,200            Exception innerException,201            string resourceString,202            params object[] arguments)203            : base(errorId, innerException, resourceString, arguments)204        {205        }206 207        #region Serialization208        /// <summary>209        /// Initializes a new instance of MethodInvocationException with serialization parameters.210        /// </summary>211        /// <param name="info">Serialization information.</param>212        /// <param name="context">Streaming context.</param>213        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]214        protected MethodInvocationException(SerializationInfo info, StreamingContext context)215        {216            throw new NotSupportedException();217        }218        #endregion Serialization219 220        #endregion ctor221 222    }223 224    /// <summary>225    /// Defines the exception thrown for errors getting the value of properties.226    /// </summary>227    public class GetValueException : ExtendedTypeSystemException228    {229        internal const string GetWithoutGetterExceptionMsg = "GetWithoutGetterException";230        internal const string WriteOnlyProperty = "WriteOnlyProperty";231        #region ctor232        /// <summary>233        /// Initializes a new instance of GetValueException with the message set234        /// to typeof(GetValueException).FullName.235        /// </summary>236        public GetValueException()237            : base(typeof(GetValueException).FullName)238        {239        }240 241        /// <summary>242        /// Initializes a new instance of GetValueException setting the message.243        /// </summary>244        /// <param name="message">The exception's message.</param>245        public GetValueException(string message)246            : base(message)247        {248        }249 250        /// <summary>251        /// Initializes a new instance of GetValueException setting the message and innerException.252        /// </summary>253        /// <param name="message">The exception's message.</param>254        /// <param name="innerException">The exception's inner exception.</param>255        public GetValueException(string message, Exception innerException)256            : base(message, innerException)257        {258        }259 260        /// <summary>261        /// Recommended constructor for the class.262        /// </summary>263        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>264        /// <param name="innerException">The inner exception.</param>265        /// <param name="resourceString">Resource string.</param>266        /// <param name="arguments">Arguments to the resource string.</param>267        internal GetValueException(268            string errorId,269            Exception innerException,270            string resourceString,271            params object[] arguments)272            : base(errorId, innerException, resourceString, arguments)273        {274        }275 276        #region Serialization277        /// <summary>278        /// Initializes a new instance of GetValueException with serialization parameters.279        /// </summary>280        /// <param name="info">Serialization information.</param>281        /// <param name="context">Streaming context.</param>282        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]283        protected GetValueException(SerializationInfo info, StreamingContext context)284        {285            throw new NotSupportedException();286        }287        #endregion Serialization288 289        #endregion ctor290 291    }292 293    /// <summary>294    /// Defines the exception thrown for errors getting the value of properties.295    /// </summary>296    public class PropertyNotFoundException : ExtendedTypeSystemException297    {298        #region ctor299        /// <summary>300        /// Initializes a new instance of GetValueException with the message set301        /// to typeof(GetValueException).FullName.302        /// </summary>303        public PropertyNotFoundException()304            : base(typeof(PropertyNotFoundException).FullName)305        {306        }307 308        /// <summary>309        /// Initializes a new instance of GetValueException setting the message.310        /// </summary>311        /// <param name="message">The exception's message.</param>312        public PropertyNotFoundException(string message)313            : base(message)314        {315        }316 317        /// <summary>318        /// Initializes a new instance of GetValueException setting the message and innerException.319        /// </summary>320        /// <param name="message">The exception's message.</param>321        /// <param name="innerException">The exception's inner exception.</param>322        public PropertyNotFoundException(string message, Exception innerException)323            : base(message, innerException)324        {325        }326 327        /// <summary>328        /// Recommended constructor for the class.329        /// </summary>330        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>331        /// <param name="innerException">The inner exception.</param>332        /// <param name="resourceString">Resource string.</param>333        /// <param name="arguments">Arguments to the resource string.</param>334        internal PropertyNotFoundException(335            string errorId,336            Exception innerException,337            string resourceString,338            params object[] arguments)339            : base(errorId, innerException, resourceString, arguments)340        {341        }342 343        #region Serialization344        /// <summary>345        /// Initializes a new instance of GetValueException with serialization parameters.346        /// </summary>347        /// <param name="info">Serialization information.</param>348        /// <param name="context">Streaming context.</param>349        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]350        protected PropertyNotFoundException(SerializationInfo info, StreamingContext context)351        {352            throw new NotSupportedException();353        }354        #endregion Serialization355        #endregion ctor356 357    }358 359    /// <summary>360    /// Defines the exception thrown for exceptions thrown by property getters.361    /// </summary>362    public class GetValueInvocationException : GetValueException363    {364        internal const string ExceptionWhenGettingMsg = "ExceptionWhenGetting";365 366        #region ctor367        /// <summary>368        /// Initializes a new instance of GetValueInvocationException with the message set369        /// to typeof(GetValueInvocationException).FullName.370        /// </summary>371        public GetValueInvocationException()372            : base(typeof(GetValueInvocationException).FullName)373        {374        }375 376        /// <summary>377        /// Initializes a new instance of GetValueInvocationException setting the message.378        /// </summary>379        /// <param name="message">The exception's message.</param>380        public GetValueInvocationException(string message)381            : base(message)382        {383        }384 385        /// <summary>386        /// Initializes a new instance of GetValueInvocationException setting the message and innerException.387        /// </summary>388        /// <param name="message">The exception's message.</param>389        /// <param name="innerException">The exception's inner exception.</param>390        public GetValueInvocationException(string message, Exception innerException)391            : base(message, innerException)392        {393        }394 395        /// <summary>396        /// Recommended constructor for the class.397        /// </summary>398        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>399        /// <param name="innerException">The inner exception.</param>400        /// <param name="resourceString">Resource string.</param>401        /// <param name="arguments">Arguments to the resource string.</param>402        internal GetValueInvocationException(403            string errorId,404            Exception innerException,405            string resourceString,406            params object[] arguments)407            : base(errorId, innerException, resourceString, arguments)408        {409        }410 411        #region Serialization412        /// <summary>413        /// Initializes a new instance of GetValueInvocationException with serialization parameters.414        /// </summary>415        /// <param name="info">Serialization information.</param>416        /// <param name="context">Streaming context.</param>417        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]418        protected GetValueInvocationException(SerializationInfo info, StreamingContext context)419        {420            throw new NotSupportedException();421        }422        #endregion Serialization423 424        #endregion ctor425 426    }427 428    /// <summary>429    /// Defines the exception thrown for errors setting the value of properties.430    /// </summary>431    public class SetValueException : ExtendedTypeSystemException432    {433        #region ctor434        /// <summary>435        /// Initializes a new instance of SetValueException with the message set436        /// to typeof(SetValueException).FullName.437        /// </summary>438        public SetValueException()439            : base(typeof(SetValueException).FullName)440        {441        }442 443        /// <summary>444        /// Initializes a new instance of SetValueException setting the message.445        /// </summary>446        /// <param name="message">The exception's message.</param>447        public SetValueException(string message)448            : base(message)449        {450        }451 452        /// <summary>453        /// Initializes a new instance of SetValueException setting the message and innerException.454        /// </summary>455        /// <param name="message">The exception's message.</param>456        /// <param name="innerException">The exception's inner exception.</param>457        public SetValueException(string message, Exception innerException)458            : base(message, innerException)459        {460        }461 462        /// <summary>463        /// Recommended constructor for the class.464        /// </summary>465        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>466        /// <param name="innerException">The inner exception.</param>467        /// <param name="resourceString">Resource string.</param>468        /// <param name="arguments">Arguments to the resource string.</param>469        internal SetValueException(470            string errorId,471            Exception innerException,472            string resourceString,473            params object[] arguments)474            : base(errorId, innerException, resourceString, arguments)475        {476        }477 478        #region Serialization479        /// <summary>480        /// Initializes a new instance of SetValueException with serialization parameters.481        /// </summary>482        /// <param name="info">Serialization information.</param>483        /// <param name="context">Streaming context.</param>484        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]485        protected SetValueException(SerializationInfo info, StreamingContext context)486        {487            throw new NotSupportedException();488        }489        #endregion Serialization490 491        #endregion ctor492 493    }494 495    /// <summary>496    /// Defines the exception thrown for exceptions thrown by property setters.497    /// </summary>498    public class SetValueInvocationException : SetValueException499    {500        #region ctor501        /// <summary>502        /// Initializes a new instance of SetValueInvocationException with the message set503        /// to typeof(SetValueInvocationException).FullName.504        /// </summary>505        public SetValueInvocationException()506            : base(typeof(SetValueInvocationException).FullName)507        {508        }509 510        /// <summary>511        /// Initializes a new instance of SetValueInvocationException setting the message.512        /// </summary>513        /// <param name="message">The exception's message.</param>514        public SetValueInvocationException(string message)515            : base(message)516        {517        }518 519        /// <summary>520        /// Initializes a new instance of SetValueInvocationException setting the message and innerException.521        /// </summary>522        /// <param name="message">The exception's message.</param>523        /// <param name="innerException">The exception's inner exception.</param>524        public SetValueInvocationException(string message, Exception innerException)525            : base(message, innerException)526        {527        }528 529        /// <summary>530        /// Recommended constructor for the class.531        /// </summary>532        /// <param name="errorId">String that uniquely identifies each thrown Exception.</param>533        /// <param name="innerException">The inner exception.</param>534        /// <param name="resourceString">Resource string.</param>535        /// <param name="arguments">Arguments to the resource string.</param>536        internal SetValueInvocationException(537            string errorId,538            Exception innerException,539            string resourceString,540            params object[] arguments)541            : base(errorId, innerException, resourceString, arguments)542        {543        }544 545        #region Serialization546        /// <summary>547        /// Initializes a new instance of SetValueInvocationException with serialization parameters.548        /// </summary>549        /// <param name="info">Serialization information.</param>550        /// <param name="context">Streaming context.</param>551        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]552        protected SetValueInvocationException(SerializationInfo info, StreamingContext context)553        {554            throw new NotSupportedException();555        }556        #endregion Serialization557 558        #endregion ctor559 560    }561 562    /// <summary>563    /// Defines the exception thrown for type conversion errors.564    /// </summary>565    public class PSInvalidCastException : InvalidCastException, IContainsErrorRecord566    {567        /// <summary>568        /// Initializes a new instance of PSInvalidCastException with serialization parameters.569        /// </summary>570        /// <param name="info">Serialization information.</param>571        /// <param name="context">Streaming context.</param>572        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]573        protected PSInvalidCastException(SerializationInfo info, StreamingContext context)574        {575            throw new NotSupportedException();576        }577 578        /// <summary>579        /// Initializes a new instance of PSInvalidCastException with the message set580        /// to typeof(PSInvalidCastException).FullName.581        /// </summary>582        public PSInvalidCastException()583            : base(typeof(PSInvalidCastException).FullName)584        {585        }586        /// <summary>587        /// Initializes a new instance of PSInvalidCastException setting the message.588        /// </summary>589        /// <param name="message">The exception's message.</param>590        public PSInvalidCastException(string message)591            : base(message)592        {593        }594        /// <summary>595        /// Initializes a new instance of PSInvalidCastException setting the message and innerException.596        /// </summary>597        /// <param name="message">The exception's message.</param>598        /// <param name="innerException">The exception's inner exception.</param>599        public PSInvalidCastException(string message, Exception innerException)600            : base(message, innerException)601        {602        }603 604        internal PSInvalidCastException(string errorId, string message, Exception innerException)605            : base(message, innerException)606        {607            _errorId = errorId;608        }609 610        internal PSInvalidCastException(611            string errorId,612            Exception innerException,613            string resourceString,614            params object[] arguments)615            : this(616                errorId, StringUtil.Format(resourceString, arguments),617                innerException)618        {619        }620 621        /// <summary>622        /// Gets the ErrorRecord associated with this exception.623        /// </summary>624        public ErrorRecord ErrorRecord625        {626            get627            {628                _errorRecord ??= new ErrorRecord(629                    new ParentContainsErrorRecordException(this),630                    _errorId,631                    ErrorCategory.InvalidArgument,632                    null);633 634                return _errorRecord;635            }636        }637 638        private ErrorRecord _errorRecord;639        private readonly string _errorId = "PSInvalidCastException";640    }641}642