More 1.1 code and NET_2_0 ifdefs removed
[mono.git] / mcs / class / System.Web / System.Web.Compilation / CompilationException.cs
index daa1ba6409ca9f44690b14cca02960816a5d7bc3..4acce3f6d74f095b7098848e2b908d53486d1808 100644 (file)
@@ -32,11 +32,14 @@ using System;
 using System.Collections;
 using System.Collections.Specialized;
 using System.CodeDom.Compiler;
+using System.Runtime.Serialization;
+using System.Security.Permissions;
 using System.Text;
 using System.Web;
 
 namespace System.Web.Compilation
 {
+       [Serializable]
        internal class CompilationException : HtmlizedException
        {
                string filename;
@@ -46,6 +49,17 @@ namespace System.Web.Compilation
                string errmsg;
                int [] errorLines;
 
+               CompilationException (SerializationInfo info, StreamingContext context)
+                       : base (info, context)
+                {
+                       filename = info.GetString ("filename");
+                       errors = info.GetValue ("errors", typeof (CompilerErrorCollection)) as CompilerErrorCollection;
+                       results = info.GetValue ("results", typeof (CompilerResults)) as CompilerResults;
+                       fileText = info.GetString ("fileText");
+                       errmsg = info.GetString ("errmsg");
+                       errorLines = info.GetValue ("errorLines", typeof (int[])) as int[];
+                }
+               
                public CompilationException (string filename, CompilerErrorCollection errors, string fileText)
                {
                        this.filename = filename;
@@ -58,6 +72,22 @@ namespace System.Web.Compilation
                {
                        this.results = results;
                }
+
+               [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
+               public override void GetObjectData (SerializationInfo info, StreamingContext ctx)
+               {
+                       base.GetObjectData (info, ctx);
+                       info.AddValue ("filename", filename);
+                       info.AddValue ("errors", errors);
+                       info.AddValue ("results", results);
+                       info.AddValue ("fileText", fileText);
+                       info.AddValue ("errmsg", errmsg);
+                       info.AddValue ("errorLines", errorLines);
+               }
+
+               public override string Message {
+                       get { return ErrorMessage; }
+               }
                
                public override string SourceFile {
                        get {
@@ -86,12 +116,19 @@ namespace System.Web.Compilation
                public override string ErrorMessage {
                        get {
                                if (errmsg == null && errors != null) {
-                                       StringBuilder sb = new StringBuilder ();
+                                       CompilerError firstError = null;
+                                       
                                        foreach (CompilerError err in errors) {
-                                               sb.Append (err);
-                                               sb.Append ("\n");
-                                       }
-                                       errmsg = sb.ToString ();
+                                               if (err.IsWarning)
+                                                       continue;
+                                               firstError = err;
+                                               break;
+                                       };
+                                       
+                                       errmsg = firstError.ToString ();
+                                       int idx = errmsg.IndexOf (" : error ");
+                                       if (idx > -1)
+                                               errmsg = errmsg.Substring (idx + 9);
                                }
 
                                return errmsg;
@@ -107,6 +144,9 @@ namespace System.Web.Compilation
                                if (errorLines == null && errors != null) {
                                        ArrayList list = new ArrayList ();
                                        foreach (CompilerError err in errors) {
+                                               if (err.IsWarning)
+                                                       continue;
+                                               
                                                if (err.Line != 0 && !list.Contains (err.Line))
                                                        list.Add (err.Line);
                                        }
@@ -130,7 +170,10 @@ namespace System.Web.Compilation
                                return results.Output;
                        }
                }
-                       
+
+               public CompilerResults Results {
+                       get { return results; }
+               }
        }
 }