< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 41
Coverable lines: 41
Total lines: 110
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 22
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
.ctor(...)0%220%
.ctor(...)0%220%
.ctor(...)0%220%
.ctor(...)0%220%
.ctor(...)0%220%
.ctor(...)0%220%
.ctor(...)0%220%
.ctor(...)100%110%
GetObjectData(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureNotFoundException.cs

#LineLine coverage
 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
 4using System.ComponentModel;
 5using System.Runtime.CompilerServices;
 6using System.Runtime.Serialization;
 7
 8namespace 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()
 018            : base(DefaultMessage)
 19        {
 020        }
 21
 22        public CultureNotFoundException(string? message)
 023            : base(message ?? DefaultMessage)
 24        {
 025        }
 26
 27        public CultureNotFoundException(string? paramName, string? message)
 028            : base(message ?? DefaultMessage, paramName)
 29        {
 030        }
 31
 32        public CultureNotFoundException(string? message, Exception? innerException)
 033            : base(message ?? DefaultMessage, innerException)
 34        {
 035        }
 36
 37        public CultureNotFoundException(string? paramName, string? invalidCultureName, string? message)
 038            : base(message ?? DefaultMessage, paramName)
 39        {
 040            _invalidCultureName = invalidCultureName;
 041        }
 42
 43        public CultureNotFoundException(string? message, string? invalidCultureName, Exception? innerException)
 044            : base(message ?? DefaultMessage, innerException)
 45        {
 046            _invalidCultureName = invalidCultureName;
 047        }
 48
 49        public CultureNotFoundException(string? message, int invalidCultureId, Exception? innerException)
 050            : base(message ?? DefaultMessage, innerException)
 51        {
 052            _invalidCultureId = invalidCultureId;
 053        }
 54
 55        public CultureNotFoundException(string? paramName, int invalidCultureId, string? message)
 056            : base(message ?? DefaultMessage, paramName)
 57        {
 058            _invalidCultureId = invalidCultureId;
 059        }
 60
 61        [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma
 62        [EditorBrowsable(EditorBrowsableState.Never)]
 63        protected CultureNotFoundException(SerializationInfo info, StreamingContext context)
 064            : base(info, context)
 65        {
 066            _invalidCultureId = (int?)info.GetValue("InvalidCultureId", typeof(int?));
 067            _invalidCultureName = (string?)info.GetValue("InvalidCultureName", typeof(string));
 068        }
 69
 70        [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma
 71        [EditorBrowsable(EditorBrowsableState.Never)]
 72        public override void GetObjectData(SerializationInfo info, StreamingContext context)
 73        {
 074            base.GetObjectData(info, context);
 075            info.AddValue("InvalidCultureId", _invalidCultureId, typeof(int?));
 076            info.AddValue("InvalidCultureName", _invalidCultureName, typeof(string));
 077        }
 78
 079        public virtual int? InvalidCultureId => _invalidCultureId;
 80
 081        public virtual string? InvalidCultureName => _invalidCultureName;
 82
 083        private static string DefaultMessage => SR.Argument_CultureNotSupported;
 84
 85        private string? FormattedInvalidCultureId =>
 086            InvalidCultureId != null ?
 087                string.Format(CultureInfo.InvariantCulture, "{0} (0x{0:x4})", (int)InvalidCultureId) :
 088                InvalidCultureName;
 89
 90        public override string Message
 91        {
 92            get
 93            {
 094                string s = base.Message;
 095                if (_invalidCultureId != null || _invalidCultureName != null)
 96                {
 097                    string valueMessage = SR.Format(SR.Argument_CultureInvalidIdentifier, FormattedInvalidCultureId);
 098                    if (s == null)
 99                    {
 0100                        return valueMessage;
 101                    }
 102
 0103                    return s + Environment.NewLineConst + valueMessage;
 104                }
 0105                return s;
 106            }
 107        }
 108    }
 109}
 110