3db110f407372209574c9d0d759f7339da851dfb
[platform/upstream/coreclr.git] / src / mscorlib / src / System / Globalization / CultureNotFoundException.cs
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 // See the LICENSE file in the project root for more information.
4
5
6 namespace System.Globalization {
7
8     using System;
9     using System.Runtime.Serialization;
10     using System.Threading;
11     using System.Diagnostics.Contracts;
12     
13     [System.Runtime.InteropServices.ComVisible(true)]
14     [Serializable]
15     public partial class CultureNotFoundException : ArgumentException, ISerializable
16     {
17         private string          m_invalidCultureName; // unrecognized culture name
18 #if !FEATURE_CORECLR
19         private Nullable<int>   m_invalidCultureId;   // unrecognized culture Lcid
20 #endif //!FEATURE_CORECLR
21
22         public CultureNotFoundException()
23             : base(DefaultMessage)
24         {
25         }
26
27         public CultureNotFoundException(String message)
28             : base(message)
29         {
30         }
31
32         public CultureNotFoundException(String paramName, String message)
33             : base(message, paramName)
34         {
35         }
36
37         public CultureNotFoundException(String message, Exception innerException)
38             : base(message, innerException)
39         {
40         }
41 #if !FEATURE_CORECLR
42         public CultureNotFoundException(String paramName, int invalidCultureId, String message)
43             : base(message, paramName)
44         {
45             m_invalidCultureId = invalidCultureId;
46         }
47
48         public CultureNotFoundException(String message, int invalidCultureId, Exception innerException)
49             : base(message, innerException)
50         {
51             m_invalidCultureId = invalidCultureId;
52         }
53 #endif //!FEATURE_CORECLR
54
55         public CultureNotFoundException(String paramName, string invalidCultureName, String message)
56             : base(message, paramName)
57         {
58             m_invalidCultureName = invalidCultureName;
59         }
60
61         public CultureNotFoundException(String message, string invalidCultureName, Exception innerException)
62             : base(message, innerException)
63         {
64             m_invalidCultureName = invalidCultureName;
65         }
66
67         protected CultureNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) {
68 #if !FEATURE_CORECLR
69             m_invalidCultureId      = (Nullable<int>) info.GetValue("InvalidCultureId", typeof(Nullable<int>));
70 #endif //!FEATURE_CORECLR
71             m_invalidCultureName    = (string) info.GetValue("InvalidCultureName", typeof(string));
72         }
73
74         [System.Security.SecurityCritical]  // auto-generated_required
75         public override void GetObjectData(SerializationInfo info, StreamingContext context) {
76             if (info==null) {
77                 throw new ArgumentNullException("info");
78             }
79             Contract.EndContractBlock();
80             base.GetObjectData(info, context);
81             Nullable<int> invalidCultureId = null;
82 #if !FEATURE_CORECLR
83             invalidCultureId = m_invalidCultureId;
84 #endif //!FEATURE_CORECLR
85             info.AddValue("InvalidCultureId", invalidCultureId, typeof(Nullable<int>));
86             info.AddValue("InvalidCultureName", m_invalidCultureName, typeof(string));
87         }
88 #if !FEATURE_CORECLR
89         public virtual Nullable<int> InvalidCultureId
90         {
91             get { return m_invalidCultureId; }
92         }
93 #endif //!FEATURE_CORECLR
94
95         public virtual string InvalidCultureName
96         {
97             get { return m_invalidCultureName; }
98         }
99
100         private static String DefaultMessage
101         {
102             get 
103             {
104                 return Environment.GetResourceString("Argument_CultureNotSupported");
105             }
106         }
107         
108         private String FormatedInvalidCultureId 
109         {
110             get
111             {
112 #if !FEATURE_CORECLR
113                 if (InvalidCultureId != null)
114                 {
115                     return String.Format(CultureInfo.InvariantCulture,
116                                         "{0} (0x{0:x4})", (int)InvalidCultureId);
117                 }
118 #endif //!FEATURE_CORECLR
119                 return InvalidCultureName;
120             }
121         }
122
123         public override String Message 
124         {
125             get 
126             {
127                 String s = base.Message;
128                 if (
129 #if !FEATURE_CORECLR
130                     m_invalidCultureId != null || 
131 #endif //!FEATURE_CORECLR
132                     m_invalidCultureName != null) 
133                 {
134                     String valueMessage = Environment.GetResourceString("Argument_CultureInvalidIdentifier", FormatedInvalidCultureId);
135                     if (s == null)
136                         return valueMessage;
137                     return s + Environment.NewLine + valueMessage; 
138                 }
139                 return s;
140             }
141         }
142
143     }
144 }