Merge pull request #1388 from schani/fix-23401
[mono.git] / mcs / class / corlib / System.Globalization / CultureNotFoundException.cs
1 //
2 // System.Globalization.CultureNotFoundException.cs
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
6 //
7 // Copyright (c) 2010 Novell (http://www.novell.com)
8 //
9
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 #if NET_4_0
30
31 using System;
32 using System.Runtime.InteropServices;
33 using System.Runtime.Serialization;
34
35 namespace System.Globalization {
36         [Serializable]
37         [ComVisible (true)]
38         public class CultureNotFoundException : ArgumentException, ISerializable {
39                 string invalid_culture_name;
40                 int? invalid_culture_id;
41
42                 public CultureNotFoundException () : base ("Culture not found")
43                 {
44                 }
45
46                 public CultureNotFoundException (string message) : base (message)
47                 {
48                 }
49
50                 protected CultureNotFoundException (SerializationInfo info, StreamingContext context)
51                                 : base (info, context)
52                 {
53                         invalid_culture_name = (string) info.GetValue ("invalid_culture_name", typeof (string));
54                         invalid_culture_id = (int?) info.GetValue ("invalid_culture_id", typeof (int?));
55                 }
56
57                 public CultureNotFoundException (string message, Exception innerException)
58                                 : base (message, innerException)
59                 {
60                 }
61
62                 public CultureNotFoundException (string paramName, string message)
63                                 : base (message, paramName)
64                 {
65                 }
66
67                 public CultureNotFoundException (string message, int invalidCultureId, Exception innerException)
68                                 : base (message, innerException)
69                 {
70                         invalid_culture_id = invalidCultureId;
71                 }
72
73                 public CultureNotFoundException (string paramName, int invalidCultureId, string message)
74                                 : base (message, paramName)
75                 {
76                         invalid_culture_id = invalidCultureId;
77                 }
78
79                 public CultureNotFoundException (string message, string invalidCultureName, Exception innerException)
80                                 : base (message, innerException)
81                 {
82                         invalid_culture_name = invalidCultureName;
83                 }
84
85                 public CultureNotFoundException (string paramName, string invalidCultureName, string message)
86                                 : base (message, paramName)
87                 {
88                         invalid_culture_name = invalidCultureName;
89                 }
90
91                 public override void GetObjectData(SerializationInfo info, StreamingContext context)
92                 {
93                         if (info == null)
94                                 throw new ArgumentNullException ("info");
95
96                         base.GetObjectData (info, context);
97                         info.AddValue ("invalid_culture_name", invalid_culture_name, typeof (string));
98                         info.AddValue ("invalid_culture_id", invalid_culture_id, typeof (int?));
99                 }
100
101                 public virtual int? InvalidCultureId {
102                         get { return invalid_culture_id; }
103                 }
104
105                 public virtual string InvalidCultureName {
106                         get { return invalid_culture_name; }
107                 }
108
109                 public override string Message {
110                         get {
111                                 if (invalid_culture_name == null && invalid_culture_id.HasValue == false)
112                                         return base.Message;
113
114                                 if (invalid_culture_name != null)
115                                         return String.Format ("Culture name {0} is invalid", invalid_culture_name);
116                                 return String.Format ("Culture ID {0} is invalid", invalid_culture_id);
117                         }
118                 }
119         }
120 }
121 #endif
122