2 // System.Configuration.ConfigurationErrorsException.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Chris Toshok (toshok@ximian.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Globalization;
36 using System.Runtime.Serialization;
37 using System.Collections;
40 namespace System.Configuration
42 /* disable the obsolete warnings about ConfigurationException */
43 #pragma warning disable 618
46 public class ConfigurationErrorsException : ConfigurationException
51 public ConfigurationErrorsException ()
55 public ConfigurationErrorsException (string message)
58 bareMessage = message;
61 protected ConfigurationErrorsException (SerializationInfo info, StreamingContext context)
62 : base (info, context)
64 filename = info.GetString ("ConfigurationErrors_Filename");
65 line = info.GetInt32 ("ConfigurationErrors_Line");
68 public ConfigurationErrorsException (string message, Exception inner)
69 : base (message, inner)
73 public ConfigurationErrorsException (string message, XmlNode node)
74 : this (message, null, GetFilename (node), GetLineNumber (node))
78 public ConfigurationErrorsException (string message, Exception inner, XmlNode node)
79 : this (message, inner, GetFilename (node), GetLineNumber (node))
83 public ConfigurationErrorsException (string message, XmlReader reader)
84 : this (message, null, GetFilename (reader), GetLineNumber (reader))
88 public ConfigurationErrorsException (string message, Exception inner, XmlReader reader)
89 : this (message, inner, GetFilename (reader), GetLineNumber (reader))
93 public ConfigurationErrorsException (string message, string filename, int line)
94 : this (message, null, filename, line)
98 public ConfigurationErrorsException (string message, Exception inner, string filename, int line)
99 : base (message, inner)
101 bareMessage = message;
102 this.filename = filename;
109 public override string BareMessage
111 get { return bareMessage; }
114 public ICollection Errors
116 get { throw new NotImplementedException (); }
119 public override string Filename
121 get { return filename; }
124 public override int Line
129 public override string Message
132 string baseMsg = base.Message;
133 string f = (filename == null) ? String.Empty : filename;
134 string l = (line == 0) ? String.Empty : (" line " + line);
136 return baseMsg + " (" + f + l + ")";
142 public static string GetFilename (XmlReader reader)
144 if (reader is XmlTextReader)
145 return ((XmlTextReader)reader).BaseURI;
150 public static int GetLineNumber (XmlReader reader)
152 if (reader is XmlTextReader)
153 return ((XmlTextReader)reader).LineNumber;
158 public static string GetFilename (XmlNode node)
160 if (!(node is IConfigXmlNode))
163 return ((IConfigXmlNode) node).Filename;
166 public static int GetLineNumber (XmlNode node)
168 if (!(node is IConfigXmlNode))
171 return ((IConfigXmlNode) node).LineNumber;
174 public override void GetObjectData (SerializationInfo info, StreamingContext context)
176 base.GetObjectData (info, context);
177 info.AddValue ("ConfigurationErrors_Filename", filename);
178 info.AddValue ("ConfigurationErrors_Line", line);
181 string bareMessage = "";
182 string filename = "";
185 #pragma warning restore