Expose missing Global/Encoding APIs in coreclr and remove empty stubs
[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         private Nullable<int>   m_invalidCultureId;   // unrecognized culture Lcid
19
20         public CultureNotFoundException()
21             : base(DefaultMessage)
22         {
23         }
24
25         public CultureNotFoundException(String message)
26             : base(message)
27         {
28         }
29
30         public CultureNotFoundException(String paramName, String message)
31             : base(message, paramName)
32         {
33         }
34
35         public CultureNotFoundException(String message, Exception innerException)
36             : base(message, innerException)
37         {
38         }
39
40         public CultureNotFoundException(String paramName, int invalidCultureId, String message)
41             : base(message, paramName)
42         {
43             m_invalidCultureId = invalidCultureId;
44         }
45
46         public CultureNotFoundException(String message, int invalidCultureId, Exception innerException)
47             : base(message, innerException)
48         {
49             m_invalidCultureId = invalidCultureId;
50         }
51
52         public CultureNotFoundException(String paramName, string invalidCultureName, String message)
53             : base(message, paramName)
54         {
55             m_invalidCultureName = invalidCultureName;
56         }
57
58         public CultureNotFoundException(String message, string invalidCultureName, Exception innerException)
59             : base(message, innerException)
60         {
61             m_invalidCultureName = invalidCultureName;
62         }
63
64         protected CultureNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) {
65             m_invalidCultureId      = (Nullable<int>) info.GetValue("InvalidCultureId", typeof(Nullable<int>));
66             m_invalidCultureName    = (string) info.GetValue("InvalidCultureName", typeof(string));
67         }
68
69         [System.Security.SecurityCritical]  // auto-generated_required
70         public override void GetObjectData(SerializationInfo info, StreamingContext context) {
71             if (info==null) {
72                 throw new ArgumentNullException("info");
73             }
74             Contract.EndContractBlock();
75             base.GetObjectData(info, context);
76             Nullable<int> invalidCultureId = null;
77             invalidCultureId = m_invalidCultureId;
78             info.AddValue("InvalidCultureId", invalidCultureId, typeof(Nullable<int>));
79             info.AddValue("InvalidCultureName", m_invalidCultureName, typeof(string));
80         }
81         public virtual Nullable<int> InvalidCultureId
82         {
83             get { return m_invalidCultureId; }
84         }
85
86         public virtual string InvalidCultureName
87         {
88             get { return m_invalidCultureName; }
89         }
90
91         private static String DefaultMessage
92         {
93             get 
94             {
95                 return Environment.GetResourceString("Argument_CultureNotSupported");
96             }
97         }
98         
99         private String FormatedInvalidCultureId 
100         {
101             get
102             {
103                 if (InvalidCultureId != null)
104                 {
105                     return String.Format(CultureInfo.InvariantCulture,
106                                         "{0} (0x{0:x4})", (int)InvalidCultureId);
107                 }
108                 return InvalidCultureName;
109             }
110         }
111
112         public override String Message 
113         {
114             get 
115             {
116                 String s = base.Message;
117                 if (
118                     m_invalidCultureId != null || 
119                     m_invalidCultureName != null) 
120                 {
121                     String valueMessage = Environment.GetResourceString("Argument_CultureInvalidIdentifier", FormatedInvalidCultureId);
122                     if (s == null)
123                         return valueMessage;
124                     return s + Environment.NewLine + valueMessage; 
125                 }
126                 return s;
127             }
128         }
129
130     }
131 }