| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.ComponentModel; |
| | | 5 | | using System.Runtime.CompilerServices; |
| | | 6 | | using System.Runtime.Serialization; |
| | | 7 | | |
| | | 8 | | namespace System.Globalization |
| | | 9 | | { |
| | | 10 | | [Serializable] |
| | | 11 | | [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] |
| | | 12 | | public class CultureNotFoundException : ArgumentException |
| | | 13 | | { |
| | | 14 | | private readonly string? _invalidCultureName; // unrecognized culture name |
| | | 15 | | private readonly int? _invalidCultureId; // unrecognized culture Lcid |
| | | 16 | | |
| | | 17 | | public CultureNotFoundException() |
| | 0 | 18 | | : base(DefaultMessage) |
| | | 19 | | { |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | public CultureNotFoundException(string? message) |
| | 0 | 23 | | : base(message ?? DefaultMessage) |
| | | 24 | | { |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | public CultureNotFoundException(string? paramName, string? message) |
| | 0 | 28 | | : base(message ?? DefaultMessage, paramName) |
| | | 29 | | { |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | public CultureNotFoundException(string? message, Exception? innerException) |
| | 0 | 33 | | : base(message ?? DefaultMessage, innerException) |
| | | 34 | | { |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | public CultureNotFoundException(string? paramName, string? invalidCultureName, string? message) |
| | 0 | 38 | | : base(message ?? DefaultMessage, paramName) |
| | | 39 | | { |
| | 0 | 40 | | _invalidCultureName = invalidCultureName; |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | public CultureNotFoundException(string? message, string? invalidCultureName, Exception? innerException) |
| | 0 | 44 | | : base(message ?? DefaultMessage, innerException) |
| | | 45 | | { |
| | 0 | 46 | | _invalidCultureName = invalidCultureName; |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | public CultureNotFoundException(string? message, int invalidCultureId, Exception? innerException) |
| | 0 | 50 | | : base(message ?? DefaultMessage, innerException) |
| | | 51 | | { |
| | 0 | 52 | | _invalidCultureId = invalidCultureId; |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | public CultureNotFoundException(string? paramName, int invalidCultureId, string? message) |
| | 0 | 56 | | : base(message ?? DefaultMessage, paramName) |
| | | 57 | | { |
| | 0 | 58 | | _invalidCultureId = invalidCultureId; |
| | 0 | 59 | | } |
| | | 60 | | |
| | | 61 | | [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma |
| | | 62 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | | 63 | | protected CultureNotFoundException(SerializationInfo info, StreamingContext context) |
| | 0 | 64 | | : base(info, context) |
| | | 65 | | { |
| | 0 | 66 | | _invalidCultureId = (int?)info.GetValue("InvalidCultureId", typeof(int?)); |
| | 0 | 67 | | _invalidCultureName = (string?)info.GetValue("InvalidCultureName", typeof(string)); |
| | 0 | 68 | | } |
| | | 69 | | |
| | | 70 | | [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma |
| | | 71 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | | 72 | | public override void GetObjectData(SerializationInfo info, StreamingContext context) |
| | | 73 | | { |
| | 0 | 74 | | base.GetObjectData(info, context); |
| | 0 | 75 | | info.AddValue("InvalidCultureId", _invalidCultureId, typeof(int?)); |
| | 0 | 76 | | info.AddValue("InvalidCultureName", _invalidCultureName, typeof(string)); |
| | 0 | 77 | | } |
| | | 78 | | |
| | 0 | 79 | | public virtual int? InvalidCultureId => _invalidCultureId; |
| | | 80 | | |
| | 0 | 81 | | public virtual string? InvalidCultureName => _invalidCultureName; |
| | | 82 | | |
| | 0 | 83 | | private static string DefaultMessage => SR.Argument_CultureNotSupported; |
| | | 84 | | |
| | | 85 | | private string? FormattedInvalidCultureId => |
| | 0 | 86 | | InvalidCultureId != null ? |
| | 0 | 87 | | string.Format(CultureInfo.InvariantCulture, "{0} (0x{0:x4})", (int)InvalidCultureId) : |
| | 0 | 88 | | InvalidCultureName; |
| | | 89 | | |
| | | 90 | | public override string Message |
| | | 91 | | { |
| | | 92 | | get |
| | | 93 | | { |
| | 0 | 94 | | string s = base.Message; |
| | 0 | 95 | | if (_invalidCultureId != null || _invalidCultureName != null) |
| | | 96 | | { |
| | 0 | 97 | | string valueMessage = SR.Format(SR.Argument_CultureInvalidIdentifier, FormattedInvalidCultureId); |
| | 0 | 98 | | if (s == null) |
| | | 99 | | { |
| | 0 | 100 | | return valueMessage; |
| | | 101 | | } |
| | | 102 | | |
| | 0 | 103 | | return s + Environment.NewLineConst + valueMessage; |
| | | 104 | | } |
| | 0 | 105 | | return s; |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | } |
| | | 109 | | } |
| | | 110 | | |