Use the right socket for the data stream
[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 #if NET_2_0
52                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
53 #endif
54                 public ConfigurationException () : this (null)
55                 {
56                         filename = null;
57                         line = 0;
58                 }
59
60 #if NET_2_0
61                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
62 #endif
63                 public ConfigurationException (string message)
64                         : base (message)
65                 {
66                 }
67
68                 protected ConfigurationException (SerializationInfo info, StreamingContext context)
69                         : base (info, context)
70                 {
71                         filename = info.GetString ("filename");
72                         line = info.GetInt32 ("line");
73                 }
74
75 #if NET_2_0
76                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
77 #endif
78                 public ConfigurationException (string message, Exception inner)
79                         : base (message, inner)
80                 {
81                 }
82
83 #if (XML_DEP)
84 #if NET_2_0
85                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
86 #endif
87                 public ConfigurationException (string message, XmlNode node)
88                         : base (message)
89                 {
90                         filename = GetXmlNodeFilename(node);
91                         line = GetXmlNodeLineNumber(node);
92                 }
93
94 #if NET_2_0
95                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
96 #endif
97                 public ConfigurationException (string message, Exception inner, XmlNode node)
98                         : base (message, inner)
99                 {
100                         filename = GetXmlNodeFilename (node);
101                         line = GetXmlNodeLineNumber (node);
102                 }
103 #endif
104 #if NET_2_0
105                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
106 #endif
107                 public ConfigurationException (string message, string filename, int line)
108                         : base (message)
109                 {
110                         this.filename = filename;
111                         this.line= line;
112                 }
113
114 #if NET_2_0
115                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
116 #endif
117                 public ConfigurationException (string message, Exception inner, string filename, int line)
118                         : base (message, inner)
119                 {
120                         this.filename = filename;
121                         this.line = line;
122                 }
123                 //
124                 // Properties
125                 //
126                 public
127 #if NET_2_0
128                 virtual
129 #endif
130                 string BareMessage {
131                         get { return base.Message; }
132                 }
133
134                 public
135 #if NET_2_0
136                 virtual
137 #endif
138                 string Filename {
139                         get { return filename; }
140                 }
141
142                 public  
143 #if NET_2_0
144                 virtual
145 #endif
146                 int Line {
147                         get { return line; }
148                 }
149
150                 public override string Message {
151                         get {
152                                 string msg;
153                                 if (filename != null && filename.Length != 0) {
154                                         if (line != 0)
155                                                 msg = BareMessage + " (" + filename + " line " + line + ")";
156                                         else
157                                                 msg = BareMessage + " (" + filename + ")";
158                                 } else {
159                                         if (line != 0)
160                                                 msg = BareMessage + " (line " + line + ")";
161                                         else
162                                                 msg = BareMessage;
163                                 }
164                                 return msg;
165                         }
166                 }
167
168                 //
169                 // Methods
170                 //
171 #if (XML_DEP)
172 #if NET_2_0
173                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
174 #endif
175                 public static string GetXmlNodeFilename (XmlNode node)
176                 {
177                         if (!(node is IConfigXmlNode))
178                                 return String.Empty;
179
180                         return ((IConfigXmlNode) node).Filename;
181                 }
182
183 #if NET_2_0
184                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
185 #endif
186                 public static int GetXmlNodeLineNumber (XmlNode node)
187                 {
188                         if (!(node is IConfigXmlNode))
189                                 return 0;
190
191                         return ((IConfigXmlNode) node).LineNumber;
192                 }
193 #endif
194                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
195                 {
196                         base.GetObjectData (info, context);
197                         info.AddValue ("filename", filename);
198                         info.AddValue ("line", line);
199                 }
200         }
201 }