Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System / System.Configuration / ConfigurationException.cs
1 //
2 // System.Configuration.ConfigurationException.cs
3 //
4 // Author:
5 //   Duncan Mak (duncan@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Globalization;
33 using System.Runtime.Serialization;
34
35 #if (XML_DEP)
36 using System.Xml;
37 #endif
38
39 namespace System.Configuration 
40 {
41         [Serializable]
42         public class ConfigurationException : SystemException
43         {
44                 // Fields
45                 readonly string filename;
46                 readonly int line;
47
48                 //
49                 // Constructors
50                 //
51                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
52                 public ConfigurationException () : this (null)
53                 {
54                         filename = null;
55                         line = 0;
56                 }
57
58                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
59                 public ConfigurationException (string message)
60                         : base (message)
61                 {
62                 }
63
64                 protected ConfigurationException (SerializationInfo info, StreamingContext context)
65                         : base (info, context)
66                 {
67                         filename = info.GetString ("filename");
68                         line = info.GetInt32 ("line");
69                 }
70
71                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
72                 public ConfigurationException (string message, Exception inner)
73                         : base (message, inner)
74                 {
75                 }
76
77 #if (XML_DEP)
78                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
79                 public ConfigurationException (string message, XmlNode node)
80                         : base (message)
81                 {
82                         filename = GetXmlNodeFilename(node);
83                         line = GetXmlNodeLineNumber(node);
84                 }
85
86                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
87                 public ConfigurationException (string message, Exception inner, XmlNode node)
88                         : base (message, inner)
89                 {
90                         filename = GetXmlNodeFilename (node);
91                         line = GetXmlNodeLineNumber (node);
92                 }
93 #endif
94                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
95                 public ConfigurationException (string message, string filename, int line)
96                         : base (message)
97                 {
98                         this.filename = filename;
99                         this.line= line;
100                 }
101
102                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
103                 public ConfigurationException (string message, Exception inner, string filename, int line)
104                         : base (message, inner)
105                 {
106                         this.filename = filename;
107                         this.line = line;
108                 }
109                 //
110                 // Properties
111                 //
112                 public virtual  string BareMessage {
113                         get { return base.Message; }
114                 }
115
116                 public virtual string Filename {
117                         get { return filename; }
118                 }
119
120                 public virtual int Line {
121                         get { return line; }
122                 }
123
124                 public override string Message {
125                         get {
126                                 string msg;
127                                 if (filename != null && filename.Length != 0) {
128                                         if (line != 0)
129                                                 msg = BareMessage + " (" + filename + " line " + line + ")";
130                                         else
131                                                 msg = BareMessage + " (" + filename + ")";
132                                 } else {
133                                         if (line != 0)
134                                                 msg = BareMessage + " (line " + line + ")";
135                                         else
136                                                 msg = BareMessage;
137                                 }
138                                 return msg;
139                         }
140                 }
141
142                 //
143                 // Methods
144                 //
145 #if (XML_DEP)
146                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
147                 public static string GetXmlNodeFilename (XmlNode node)
148                 {
149                         if (!(node is IConfigXmlNode))
150                                 return String.Empty;
151
152                         return ((IConfigXmlNode) node).Filename;
153                 }
154
155                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
156                 public static int GetXmlNodeLineNumber (XmlNode node)
157                 {
158                         if (!(node is IConfigXmlNode))
159                                 return 0;
160
161                         return ((IConfigXmlNode) node).LineNumber;
162                 }
163 #endif
164                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
165                 {
166                         base.GetObjectData (info, context);
167                         info.AddValue ("filename", filename);
168                         info.AddValue ("line", line);
169                 }
170         }
171 }