Merge pull request #2781 from alexanderkyte/inflated_method_header_leak
[mono.git] / mcs / class / System.Web / System.Web.Compilation / ParseException.cs
1 //
2 // System.Web.Compilation.ParseException
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 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.IO;
33 using System.Runtime.Serialization;
34 using System.Security.Permissions;
35
36 namespace System.Web.Compilation
37 {
38         [Serializable]
39         internal class ParseException : HtmlizedException
40         {
41                 ILocation location;
42                 string fileText;
43
44                 ParseException (SerializationInfo info, StreamingContext context)
45                         : base (info, context)
46                 {
47                 }
48                 
49                 public ParseException (ILocation location, string message)
50                         : this (location, message, null)
51                 {
52                         location = new Location (location);
53                 }
54
55
56                 public ParseException (ILocation location, string message, Exception inner)
57                         : base (message, inner)
58                 {
59                         this.location = location;
60                 }
61
62                 public override string Title {
63                         get { return "Parser Error"; }
64                 }
65
66                 public override string Description {
67                         get {
68                                 return "Error parsing a resource required to service this request. " +
69                                        "Review your source file and modify it to fix this error.";
70                         }
71                 }
72
73                 public override string ErrorMessage {
74                         get { return Message; }
75                 }
76
77                 public override string SourceFile {
78                         get { return FileName; }
79                 }
80                 
81                 public override string FileName {
82                         get {
83                                 if (location == null)
84                                         return null;
85
86                                 return location.Filename;
87                         }
88                 }
89
90                 public override string FileText {
91                         get {
92                                 if (fileText != null)
93                                         return fileText;
94
95                                 string text = location != null ? location.FileText : null;
96                                 if (text != null && text.Length > 0)
97                                         return text;
98                                 
99                                 if (FileName == null)
100                                         return null;
101
102                                 //FIXME: encoding
103                                 using (TextReader reader = new StreamReader (FileName))
104                                         fileText = reader.ReadToEnd ();
105                                 return fileText;
106                         }
107                 }
108
109                 public override int [] ErrorLines {
110                         get {
111                                 if (location == null)
112                                         return null;
113
114                                 return new int [] {location.BeginLine, location.EndLine};
115                         }
116                 }
117
118                 public override bool ErrorLinesPaired {
119                         get { return true; }
120                 }
121
122                 [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
123                 public override void GetObjectData (SerializationInfo info, StreamingContext ctx)
124                 {
125                         base.GetObjectData (info, ctx);
126                 }
127         }
128 }
129